PDA

Click to See Complete Forum and Search --> : Expandable listbox groups


Sybre
Sep 3rd, 2009, 09:04 AM
I have a listbox which is binding to a datatable and uses grouping (currently two levels) to display the results. This works fine but I'm wondering if it's possible to add expanders to specific levels of the grouping (a little like a treevie) - this is just my test app, the final one will have more than two levels of grouping and I don't want all levels to be expandable/collapsible. I kind of thought I might be able to do it in the individual GroupStyles but don't quite know how...

vb:

'Set the ItemSource
ListBox1.ItemsSource = oSet.Tables("tblChild").DefaultView
'Setup the grouping
Dim oView As ICollectionView
oView = CollectionViewSource.GetDefaultView(oListBox.ItemsSource)
oView.GroupDescriptions.Add(New PropertyGroupDescription("Categories"))
oView.GroupDescriptions.Add(New PropertyGroupDescription("Grouper"))


XAML:
<ListBox Name="ListBox1" HorizontalContentAlignment="Stretch" HorizontalAlignment="Left" Width="355">
<ListBox.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Foreground="White" Background="SteelBlue" Margin="0,5,0,0" Padding="3"></TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Name}" FontWeight="Bold" Foreground="White" Background="Maroon" Margin="0,5,0,0" Padding="3"></TextBlock>
</DataTemplate>
</GroupStyle.HeaderTemplate>
</GroupStyle>
</ListBox.GroupStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Border Margin="5" BorderThickness="1" BorderBrush="SteelBlue" CornerRadius="4">
<StackPanel>
<CheckBox></CheckBox>
<TextBlock Text="{Binding Path=Categories}"></TextBlock>
<TextBlock Text="{Binding Path=Info}"></TextBlock>
<TextBlock Text="{Binding Path=Grouper}"></TextBlock>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>

</ListBox>