WPF Listbox grouping

2019-05-13 20:59发布

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

1条回答
聊天终结者
2楼-- · 2019-05-13 21:45

You can try with this code

<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

查看更多
登录 后发表回答