推荐文章

Winform 全屏显示

Winform 全屏显示

Winform程序无边框、置顶、全屏显示
WPF之Image控件

WPF之Image控件

Image控件加载图片包括加载动态图片,加载静态图片两种方式。加载动态图片通过生成一个BitmapImage,创建该对象后,赋给Image的Source即可。加载的形式:BitmapImage myBitmapImage =new BitmapImage();myBitmapImage.BeginInit();取得数据库存储的图片字段,MSSQL的Image类型Byte[] mybyte = Re
wpf list<T>与ObservableCollection<T>的区别

wpf list<T>与ObservableCollection<T>的区别

List《T》与ObservableCollection《T》的用法基本上是一样的。区别:list《T》:当T继承于INotifyPropertyChanged时,如果list《T》中的属性发生改变,则通知UI属性值已发生改变。但当list《T》添加一项时,list《T》就无法通知前端UI了(此时,ObservableCollection《T》闪亮登场)。ObservableCollection《
WPF调用线程复制文件并显示进度条

WPF调用线程复制文件并显示进度条

在WPF中复制文件时,如何调用线程,显示进度条。《Window x:Class="WpfThreadTest.MainWindow"xmlns="http:schemas.microsoft.comwinfx2006xamlpresentation"xmlns:x="http:schemas.microsoft.comwinfx2006xaml"Title="MainWindow" Closed=
WPF中对XML的读写

WPF中对XML的读写

已知有一个XML文件(bookste.xml)如下:《?xmlversion="1.0" encoding="gb2312"?》《bookste》《bookgenre="fantasy" ISBN="236314"》《title》OberonsLegacy《title》《auth》Cets,Eva《auth》《price》5.95《price》《book》《bookste》 1、往《bookste

WPF中listbox多列展示实现方法

日期:2018-07-05 点击:2495 来源:

wpf中ListBox默认是只有一列显示子项内容的,通过wpf灵活的样式机制,是可以将listbox改为多列显示,这也是wpf样式的强大之处。

当然,实现多列子项展示,也可以改为使用listView或者GridView。

下面是一个简单的方法,通过样式更改listbox的itemsPanel,使他显示多列。

<ListBox

  <ListBox.ItemsPanel

    <ItemsPanelTemplate

      <UniformGrid Columns="3"/

    </ItemsPanelTemplate

  </ListBox.ItemsPanel

  

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

  <ListBoxItem>Item</ListBoxItem

< /ListBox>



<ListBox Grid.Column="2" Grid.RowSpan="2" FontSize="18" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" >

            <ListBox.ItemContainerStyle>

                <Style TargetType="{x:Type ListBoxItem}">

                    <Setter Property="Background" Value="#FFEEF2BA"></Setter>

                    <Setter Property="Padding" Value="5"></Setter>

                    <Style.Triggers>

                        <Trigger Property="ItemsControl.AlternationIndex" Value="1">

                            <Setter Property="Background" Value="LightBlue"></Setter>

                        </Trigger>

                        <Trigger Property="IsFocused" Value="True"/>

                        <Trigger Property="IsSelected" Value="True">

                            <Setter Property="Background" Value="SteelBlue" />

                            <Setter Property="Foreground" Value="Red"></Setter>

                            <Setter Property="BorderBrush" Value="Black"></Setter>

                            <Setter Property="BorderThickness" Value="1"></Setter>

                            <Setter Property="Padding" Value="5"></Setter>

                        </Trigger>

                    </Style.Triggers>

                </Style>

            </ListBox.ItemContainerStyle>

            <ListBoxItem Tag="1">快餐类</ListBoxItem>

            <ListBoxItem Tag="2">饮料类</ListBoxItem>

            <ListBoxItem Tag="3">小炒类</ListBoxItem>

            <ListBoxItem Tag="4">汤类</ListBoxItem>

            <ListBoxItem Tag="4">单点类</ListBoxItem>

            <ListBoxItem Tag="4">套餐类</ListBoxItem>

            <ListBoxItem Tag="4">早餐类</ListBoxItem>

            <ListBoxItem Tag="4">酒水</ListBoxItem>

            <ListBoxItem Tag="4">美团套餐</ListBoxItem>

            <ListBoxItem Tag="4">面类</ListBoxItem>

            <ListBoxItem Tag="4">小吃类</ListBoxItem>

            <ListBoxItem Tag="4">员工餐</ListBoxItem>

            <ListBoxItem Tag="4">套餐汤类套餐汤类</ListBoxItem>

            <ListBoxItem Tag="1">快餐类</ListBoxItem>

            <ListBoxItem Tag="2">饮料类</ListBoxItem>

            <ListBoxItem Tag="3">小炒类</ListBoxItem>

            <ListBoxItem Tag="4">汤类</ListBoxItem>

            <ListBoxItem Tag="4">单点类</ListBoxItem>

            <ListBoxItem Tag="4">套餐类</ListBoxItem>

            <ListBoxItem Tag="4">早餐类</ListBoxItem>

            <ListBoxItem Tag="4">酒水</ListBoxItem>

            <ListBoxItem Tag="4">美团套餐</ListBoxItem>

            <ListBoxItem Tag="4">面类</ListBoxItem>

            <ListBoxItem Tag="4">小吃类</ListBoxItem>

            <ListBoxItem Tag="4">员工餐</ListBoxItem>

            <ListBoxItem Tag="4">套餐汤类套餐汤类</ListBoxItem>

        </ListBox>


这篇文档对您是否有帮助?

Winform 全屏显示

Winform 全屏显示

Winform程序无边框、置顶、全屏显示
WPF之Image控件

WPF之Image控件

Image控件加载图片包括加载动态图片,加载静态图片两种方式。加载动态图片通过生成一个BitmapImage,创建该对象后,赋给Image的Source即可。加载的形式:BitmapImage myBitmapImage =new BitmapImage();myBitmapImage.BeginInit();取得数据库存储的图片字段,MSSQL的Image类型Byte[] mybyte = Re
wpf list<T>与ObservableCollection<T>的区别

wpf list<T>与ObservableCollection<T>的区别

List《T》与ObservableCollection《T》的用法基本上是一样的。区别:list《T》:当T继承于INotifyPropertyChanged时,如果list《T》中的属性发生改变,则通知UI属性值已发生改变。但当list《T》添加一项时,list《T》就无法通知前端UI了(此时,ObservableCollection《T》闪亮登场)。ObservableCollection《
WPF调用线程复制文件并显示进度条

WPF调用线程复制文件并显示进度条

在WPF中复制文件时,如何调用线程,显示进度条。《Window x:Class="WpfThreadTest.MainWindow"xmlns="http:schemas.microsoft.comwinfx2006xamlpresentation"xmlns:x="http:schemas.microsoft.comwinfx2006xaml"Title="MainWindow" Closed=
WPF中对XML的读写

WPF中对XML的读写

已知有一个XML文件(bookste.xml)如下:《?xmlversion="1.0" encoding="gb2312"?》《bookste》《bookgenre="fantasy" ISBN="236314"》《title》OberonsLegacy《title》《auth》Cets,Eva《auth》《price》5.95《price》《book》《bookste》 1、往《bookste