定义5行
<Grid.RowDefinitions>
<RowDefinition Height="80"/>
<RowDefinition Height="80"/>
<RowDefinition Height="80"/>
<RowDefinition Height="80"/>
<RowDefinition Height="80"/>
</Grid.RowDefinitions>
在上面5行分别放上5个button,
<Button Grid.Row="0" Grid.Column="0" Margin="20" />
<Button Grid.Row="1" Grid.Column="0" Margin="5 30" />
<Button Grid.Row="2" Grid.Column="0" Margin="5 30 100 0" />
<Button Grid.Row="3" Grid.Column="0" Margin="20" Height="40" Width="100" />
<Button Grid.Row="4" Grid.Column="0" Margin="20" Height="40" Width="100" HorizontalAlignment="Left" />
下面是 button垂直方向对齐或拉伸
<Button Grid.Row="0" Grid.Column="0" Height="50" Width="150" VerticalAlignment="Top" Content="Top顶部对齐" />
<Button Grid.Row="1" Grid.Column="0" Height="50" Width="150" VerticalAlignment="Bottom" Content="Top底部对齐" />
<Button Grid.Row="2" Grid.Column="0" Height="50" Width="150" VerticalAlignment="Center" Content="Top中间对齐" />
<Button Grid.Row="3" Grid.Column="0" Width="150" VerticalAlignment="Stretch" Content="Stretch伸展" />
<Button Grid.Row="4" Grid.Column="0" Height="50" Width="150" VerticalAlignment="Stretch" Content="Stretch伸展并设置高度" />

本文详细介绍了WPF中使用Grid进行布局的方法,并展示了如何通过RowDefinitions定义多行,以及如何设置Button的Grid.Row属性来实现按钮的垂直排列。此外,还探讨了Button的Margin、Height、Width及VerticalAlignment等属性的用法。
199

被折叠的 条评论
为什么被折叠?



