您的位置:首页 > 其它

【WPF】设置ListBox容器子控件的布局

2017-01-21 10:05 295 查看
需求:像下图那样显示把一组内容装入ListBox中显示。要求用WrapPanel横向布局,顺序如图中的数字。



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

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

<TextBox Text="测试" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox Text="测试" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox Text="测试" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox Text="测试" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox Text="测试" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox Text="测试" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<TextBox Text="测试" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</ListBox>


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

重要的参考:

http://www.cnblogs.com/qishichang/archive/2010/09/30/1839040.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  wpf