【转】WPF中ListBox 横排的方法

【转】WPF中ListBox 横排的方法

2011-09-08 08:50  Lecone.JY.HU  阅读(395)  评论(0)  编辑  收藏

 如果只是单纯的让ListBox可以横向配列,这样很简单,只需要更改ListBox的ItemsPanel模板就可以,例如:

<ListBox>
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

 

  但是这样的修改,ListBox只能横向排列,不会根据宽度自动换行,如果想要横向排列的ListBox支持根据宽度自动换行的话,需要这样写:

<ListBox>
    <ListBox.Template>
        <ControlTemplate TargetType="{x:Type ListBox}">
            <WrapPanel Orientation="Horizontal" IsItemsHost="True"/>
        </ControlTemplate>
    </ListBox.Template>
</ListBox>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值