2021-08-08 WPF控件专题 DockPanel 控件详解

举报
愚公搬代码 发表于 2021/10/18 23:59:40 2021/10/18
【摘要】 1.DockPanel 控件介绍 停靠面板,顶部 左边 右边 下边 中间 Winform Dock: Top Left Right Bottom 特点:先添加的子元素,优先占用边角(优先占有权),所有...

1.DockPanel 控件介绍

停靠面板,顶部 左边 右边 下边 中间 Winform Dock: Top Left Right Bottom

特点:先添加的子元素,优先占用边角(优先占有权),所有子元素区域不会重叠

与其他布局控件结合使用,
应用:布局自适应页面

2.具体案例

<Grid>
<!--LastChildFill 默认为true  最后的元素完全填充剩余的部分-->
<!--如果在同一侧,依靠了多个元素,它们按顺序依次排列-->
    <DockPanel LastChildFill="True">
            <StackPanel DockPanel.Dock="Top" Background="LightBlue" Height="50">
                    <Label Content="Top"/>
            </StackPanel>
            <StackPanel DockPanel.Dock="Bottom" Background="OrangeRed"  Height="50">
                    <Label Content="Bottom"/>
            </StackPanel>
            <StackPanel DockPanel.Dock="Left" Background="LightGray" Width="100">
                    <Label Content="Left"/>
            </StackPanel>
            <StackPanel DockPanel.Dock="Left" Background="LightGray" Width="100">
                    <Label Content="Left2"/>
            </StackPanel>
            <StackPanel DockPanel.Dock="Right" Background="Green" Width="100">
                    <Label Content="Right"/>
            </StackPanel>

            <Grid Background="BlueViolet">
                    <Label Content="Content"/>
            </Grid>
            <Grid Background="Orange">
                    <DockPanel LastChildFill="True">
                            <Button  Content="top" Height="30" DockPanel.Dock="Top"/>
                            <Button  Content="bottom" Height="30" DockPanel.Dock="Bottom"/>
                            <Button  Content="left" Width="30" DockPanel.Dock="Left"/>
                            <Button  Content="right" />
                    </DockPanel>
            </Grid>
    </DockPanel>
</Grid>

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33

文章来源: codeboy.blog.csdn.net,作者:愚公搬代码,版权归原作者所有,如需转载,请联系作者。

原文链接:codeboy.blog.csdn.net/article/details/119523087

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

举报
请填写举报理由
0/200