WrapPanel內部採用流式佈局,使用orientation屬性控制流延伸方向,用HorizontalAlignment和VerticalAlignment兩個屬性控制內部控件的對齊,例子如下
<WrapPanel>
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
<Button Width="50" Height="50" Content="OK" />
</WrapPanel>
效果如下,改變窗口大小,內部控件的位置會自動調整
同樣的代碼,改成垂直佈局後的效果