WPF DockPanel学习(北盟网校)

在北盟网校上进行学习C#,也写出了一些小项目 今天学习了DockPanel的用法

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>

如果使用这种方式 北南的宽度会占满整个DockPanel  如果是下面这种方式的话 东西的高度会占满整个屏幕的高度

 <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"/>
       最后再设置中,因为要在DockPanel中设置 dockpanel的LastChildFill="True“
原网址:http://www.bamn.cn/course/volume/3917
        <Button x:Name="button3" Content="中"/>
    </DockPanel>

猜你喜欢

转载自blog.csdn.net/qq_33407246/article/details/82533506