zoukankan      html  css  js  c++  java
  • 【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

  • 相关阅读:
    1121 Django基本
    1121 爬虫简单面条版
    1118 DOM
    1114 CSS基础
    1116 前端的练习--博客界面
    1112 前端基础之标签
    仿优酷错误
    1107 python自定义实现ORM
    cesm1_2_2在南信大大型机上的移植以及运行简单case的步骤
    ERROR:105: Unable to locate a modulefile for 'xxx'
  • 原文地址:https://www.cnblogs.com/guxin/p/wpf-listbox-set-flowlayout-by-wrappanel.html
Copyright © 2011-2022 走看看