WPF列表框分组 [英] WPF Listbox grouping

查看:356
本文介绍了WPF列表框分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在下面的列表框中显示.这种情况是它将有多个组,然后是水平对齐的项目.

I need to display in the list box like below. The scenario is it will have multiple groups followed by items with alignment horizontally.

    GroupA
      GroupA Description
    GroupB
      GroupB Description
    Items Available
     ItemA ItemB ITemC

推荐答案

您可以尝试使用此代码

<Style x:Key="ContainerStyle" TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Expander Header="{Binding ....}" IsExpanded="True">
                            <ItemsPresenter />
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
</Style>


<ListBox x:Name="lbPersonList" Margin="19,17,162,25" AlternationCount="2">
            <ListBox.GroupStyle>
                <GroupStyle ContainerStyle="{StaticResource ContainerStyle}"/>
            </ListBox.GroupStyle>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding ...}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
</ListBox>

注意:调整您对代码的绑定

Nota : adjust your binding on your code

这篇关于WPF列表框分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆