栈式面板:StackPanel就是将控件按照行或列来顺序排列,但不会换行。
通过设置面板的Orientation属性设置了两种排列方式:横排(Horizontal默认的)和竖排(Vertical)。
默认情况下,水平排列时,每个元素都与面板一样高;垂直排列时,每个元素都与面板一样宽。如果包含的元素超过了面板空间,它只会截断多出的内容。
元素的Margin属性用于使元素之间产生一定得间隔,当元素空间大于其内容的空间时,剩余空间将由HorizontalAlignment和 VerticalAlignment属性来决定如
特点:
每个元素各占一行或者一列
代码:
<Window x:Class="RowDefinitions.StackPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:RowDefinitions"
mc:Ignorable="d"
Title="StackPanel" Height="300" Width="300">
<!--StackPanel:栈式面板-->
<StackPanel>
<!--Orientation 设置停靠方向 Vertical 垂直停靠-->
<GroupBox Header="小垃圾网站">
<StackPanel Orientation="Vertical">
<!--Button 按钮 -->
<Button Content=".Nmw1"></Button>
<Button Content=".Nmw2"></Button>
<Button Content=".Nmw3"></Button>
<Button Content=".Nmw4"></Button>
</StackPanel>
</GroupBox>
<GroupBox Header="垃圾连接" Height="Auto" >
<!--Horizontal 水平停靠-->
<StackPanel Orientation ="Horizontal">
<Button Content="gg1"></Button>
<Button Content="gg2"></Button>
<Button Content="gg3"></Button>
<Button Content="gg"></Button>
<Button Content="gg4"></Button>
</StackPanel>
</GroupBox>
</StackPanel>
</Window>
效果: