WPF控件之WrapPanel的用法

WrapPanel是一个可以行填充或列填充的布局组件,它可以自动换行或换列。例如,给定的代码示例展示了如何将10个按钮按两行排列。当按钮的高度不同时,行高会依据最高的按钮调整。此外,通过设置orientation属性为Vertical,可以实现垂直排列,按钮的宽度会影响列宽。
摘要由CSDN通过智能技术生成

简单来说,WrapPanel就是一个可以行填充,自动换行。或者列填充,自动换列的一个布局容器。

如下所示,它会自动将10个button分成2行

<WrapPanel>
        <Button Content="button1" />
        <Button Content="button2" />
        <Button Content="button3" />
        <Button Content="button4" />
        <Button Content="button5" />
        <Button Content="button6" />
        <Button Content="button7" />
        <Button Content="button8" />
        <Button Content="button9" />
        <Button Content="butto10" />        
    </WrapPanel>

 如果将其中一个Button设置不一样的高度,那么整列的行高会以最高的这个为主

    <WrapPanel>
        <Button Content="button1" Height="20" />
        <Button Content="button2" Height="20"/>
        <Button Content="button3" Height="20"/>
        <Button Content="button4" Height="30"/>
        <Button Content="button5" Height="20"/>
        <Button Content="button6" />
        <Button Content="button7" />
        <Button Content="button8" />
        <Button Content="button9" />
        <Button Content="butto10" />        
    </WrapPanel>

 

下面来看垂直方向排列,在wrapPanel 后加上属性orientation="Vertical":

  <WrapPanel Orientation="Vertical">
        <Button Content="button1"  />
        <Button Content="button2" />
        <Button Content="button3"/>
        <Button Content="button4" />
        <Button Content="button5" Width="100" />
        <Button Content="button6" />
        <Button Content="button7" />
        <Button Content="button8" />
        <Button Content="button9" Width="80"/>
        <Button Content="butto10" />        
    </WrapPanel>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值