I have a grid, where I want two rows, such that the lower row is 52 pixels high开发者_如何学Go, and the upper row's height takes up the remaining space. For example, if the Grid's height is 100 pixels, the upper row is 48 pixels and the lower row is 52 pixels.
The height of the Grid is guaranteed to be atleast 53 pixels. Currently, my XAML code looks like:
<Grid Height="{TemplateBinding Height}">
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="52"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.5*"></ColumnDefinition>
<ColumnDefinition Width="0.5*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0">Upper</TextBlock>
<TextBlock Grid.Row="0" Grid.Column="1">Upper</TextBlock>
<StackPanel Grid.Row="1" Grid.Column="0" Background="#1CFFFFFF">
<TextBlock>Lower</TextBlock>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Background="#1CFFFFFF">
<TextBlock>Lower</TextBlock>
</StackPanel>
</Grid>
The problem is that the upper row takes only the amonut neccessary for the TextBlocks to show up, and the StackPanel's in the lower row stretch to fill up the height of the grid. This is part of a custom control and hence the height of the grid is set as {TemplateBinding Height}
.
And I do need the contents of the lower row to be StackPanels.
Attempts from my side that haven't worked:
- Setting the heights of the lower StackPanels as 52.
- Trying different values for the
Orientation
parameter of the StackPanel [no clue why I did this, though]. - Setting
MaxHeight
,MinHeight
as 52 on the 2ndRowDefinition
.
Any help is greatly appreciated.
精彩评论