ravi shankar
ravi shankar

Reputation: 69

WPF Listbox grouping

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

Upvotes: 3

Views: 4738

Answers (1)

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

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

Upvotes: 1

Related Questions