Reputation: 5550
Please have a look at my code below:
<Border Background="#242328" CornerRadius="10" Opacity="0.9">
<Grid Width="400">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="80"/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding [someViewModel].Title}" Margin="0,20,0,20"/>
<StackPanel Grid.Row="1" Orientation="Vertical">
<TextBlock Margin="20,0,0,0" Text="{Binding [someViewModel].AnotherText}"/>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Vertical">
<Image Source="{Binding [someViewModel].source}" Width="100" Height="100"/>
<TextBlock Margin="20,0,0,0" Text="{Binding [someViewModel].AnotherText2}"/>
</StackPanel>
<Grid Grid.Row="3" Width="250" Margin="0,10,10,10">
<Button Width="120" Height="50" Background="#638699" Content="OK" FontSize="18"/>
</Grid>
</Grid>
</Border>
Output of the code above:
Now my question very simple, why there is empty space above the button? I've already set all RowDefinition Height="Auto"
, when there isn't any value in my variable, shouldn't the box shrink to left only button?
Please note that all the variable such as [someViewModel].Title, [someViewModel].AnotherText, [someViewModel].AnotherText2, [someViewModel].Source will be null
Upvotes: 0
Views: 1291
Reputation: 6155
Have a look at your designer and you will see something like this
Your TextBlock and StackPanels will be rendered and it doesn't matter if they have a value or not. If you want to hide them when they don't have a value you can use an IValueConverter to determine their visibilty based on their content.
Upvotes: 4
Reputation: 964
Some of your controls in the Auto
sized rows do have a height > 0 even if they don't display anything. This causes the calculated row height to also be > 0.
For example the Margin
on your TextBlock
causes a calculated height.
Also the Image
control height is set to 100, no matter if you assign a source or not.
Upvotes: 1