You can do this using the nested ItemsControls bound to the PagedCollectionView .
Let's say I have a data source - MyItems - with the fields: Category , Section and Option . I can create a PagedCollectionView from IEnumerable(of MyItems) and specify which fields should be grouped.
Dim original As IEnumerable(Of MyItems) = GetMyItems() Dim pcv = New PagedCollectionView(original) pcv.GroupDescriptions.Add(New PropertyGroupDescription("Category")) pcv.GroupDescriptions.Add(New PropertyGroupDescription("Section"))
Then I bind my first ItemsControl to the PagedCollectionView
hisMyItems.ItemsSource = pcv.Groups
PCV creates a nested hierarchy of the type:
-Name -Items
where Name is the value in the grouped field, and Items contains strings / objects in this group. I think you can also create PCV in xaml if you want.
xaml will look something like this:
<controls:HeaderedItemsControl x:Name="hisMyItems" Header="{Binding Name}" ItemsSource="{Binding Items}" > <controls:HeaderedItemsControl.ItemTemplate> <DataTemplate> <controls:HeaderedItemsControl Header="{Binding Name}" ItemsSource="{Binding Items}" ItemsPanel="{StaticResource ItemsPanelTemplate1}" > <controls:HeaderedItemsControl.ItemTemplate> <DataTemplate> <Button Content="{Binding Option}" /> </DataTemplate> </controls:HeaderedItemsControl.ItemTemplate> </controls:HeaderedItemsControl> </DataTemplate> </controls:HeaderedItemsControl.ItemTemplate> </controls:HeaderedItemsControl>
Hope this makes sense. I tried to simplify things from my actual application, but I could make some copy errors. Obviously, you can use regular ItemsControl controls or other controls and customize them using templates, etc.
Geoff appleford
source share