注意两个参数:
Orientation :控制排列是水平方向,还是垂直方向(Horizontal 水平方向 Vertical垂直方向)
FlowDirection:控制控件排序是从右往左还是从左往右,写两个简单的demo如下:
<Window x:Class="StackPanel_One.MainWindow"
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:StackPanel_One"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation="Horizontal">
<Button Width="40" Height="40"></Button>
<Button Width="40" Height="40"></Button>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Vertical">
<Button Width="40" Height="40"></Button>
<Button Width="40" Height="40"></Button>
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal" FlowDirection ="RightToLeft">
<Button Width="40" Height="40"></Button>
<Button Width="40" Height="40"></Button>
</StackPanel>
<StackPanel Grid.Column="3" Orientation="Vertical" FlowDirection="RightToLeft">
<Button Width="40" Height="40"></Button>
<Button Width="40" Height="40"></Button>
</StackPanel>
</Grid>
</Window>
效果如下: