DockPanel是吧界面分为东南西北中 五个位置
通过这种里面的子控件的 DockPanel.Dock 就可以配置显示不同的位置
另外 子控件的位置 也会影响布局
中间的控件 可以占满整个控件
我们设置DockPanel的 LastChildFill设为true 这样 最后一个控件 就占满了中间的区域
<DockPanel LastChildFill="True">
<Button x:Name="button1" Content="北" Height="30" DockPanel.Dock="Top"/>
<Button x:Name="button4" Content="南" Height="30" DockPanel.Dock="Bottom"/>
<Button x:Name="button2" Content="东" Width="50" DockPanel.Dock="Right"/>
<Button x:Name="button" Content="西" Width="50" DockPanel.Dock="Left"/>
<Button x:Name="button3" Content="中"/>
</DockPanel>Code language: HTML, XML (xml)
如果南北的按钮在dockpanel里面在前面出现,这样南北的宽就会占满整个dockpanel的宽度
如果东西按钮在dockpanel的前面 则东西的高度占满dockpanel的高度
另外 中间的控件
应该放在后面 因为需要设置
dockpanel的LastChildFill=”True”
<DockPanel LastChildFill="True">
<Button x:Name="button2" Content="东" Width="50" DockPanel.Dock="Right"/>
<Button x:Name="button" Content="西" Width="50" DockPanel.Dock="Left"/>
<Button x:Name="button1" Content="北" Height="30" DockPanel.Dock="Top"/>
<Button x:Name="button4" Content="南" Height="30" DockPanel.Dock="Bottom"/>
<Button x:Name="button3" Content="中"/>
</DockPanel>Code language: HTML, XML (xml)
Previous: 06-WrapPanel面板的使用和计算器界面设计
Next: 08-布局的嵌套和一个聊天窗口的实现