我有两个网格行,它们的内容会有所不同。
我希望顶行的内容垂直居中于行内。
底行垂直对齐底部。
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="60*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" VerticalAlignment="Top">
<Grid VerticalAlignment="Center">
<StackPanel>
...
</StackPanel>
</Grid>
</Grid>
<StackPanel Grid.Row="1" VerticalAlignment="Bottom" d:LayoutOverrides="GridBox">
...
</StackPanel>
</Grid>
这应该是它的样子。
+-----------------------------+ +--------------------------------+
| | | |
| | | |
| | | |
| Content Centered | | |
| | | |
| | | Content Centered |
| | | |
+-----------------------------+ or | |
| | | |
| | | |
| | | |
| | +--------------------------------+
| | | |
| Content at the bottom | | Content at the bottom |
+-----------------------------+ +--------------------------------+
行的内容可能会有所不同,我在某些时候使用过rowdefinitions但它没有用,因为我不知道任何一行的固定高度。
答案 0 :(得分:1)
因此,正如我所说,除非您使用定义一系列Grid.Row="1"
元素,否则RowDefinition
无效。无论如何,你描述的问题很容易,
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid VerticalAlignment="Center">
<!-- stuff here is center aligned -->
</Grid>
</Grid>
<Grid Grid.Row="1">
<Grid VerticalAlignment="Bottom">
<!-- stuff here is bottom aligned -->
</Grid>
</Grid>
</Grid>