【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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM