Silverlight: Datagrid as a grouping in ItemsControl

Can I group items in an ItemsControl or Listbox in Silverlight? These controls are bound to a DomainDataSource object.

Or are there any third party controls that do this?

UPDATE:

This is the user interface I'm trying to create.

alt text

+7
silverlight grouping listbox itemscontrol
source share
4 answers

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.

+5
source share

The DataGrid control supports grouping.

Tim Heyer has a nice datagrid grouping blog. link text

0
source share

Perhaps the control you are really looking for is Accordian Control from Toolkit .

See the sample Accordion Behavior here .

Please note that the actual look is as stylish as any other control. The main function is to group categories of elements that would otherwise be a direct list.

0
source share

All Articles