【WPF】设置ListBox容器Item的流式布局

需求:像下图那样显示把一组内容装入ListBox中显示。要求用WrapPanel横向布局,顺序如图中的数字。

问题:ListBox默认的布局是从上往下单列的,所以需要设置布局。

<ListBox x:Name="HousePlansLB">
    <ListBox.Template>
        <ControlTemplate TargetType="ListBox">
            <WrapPanel Width="600" Orientation="Horizontal" IsItemsHost="True"/>
        </ControlTemplate>
    </ListBox.Template>

    <TextBox Text="测试1" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="测试2" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="测试3" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="测试4" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="测试5" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="测试6" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="测试7" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</ListBox>

实际使用中,还要给ListBox设置它的ItemsSource绑定到ViewModel中的某个列表,不会是向上面那样直接手打一串的TextBox的。

重要的参考:

http://www.cnblogs.com/qishichang/archive/2010/09/30/1839040.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值