Grouping bound collections
The previous recipe used the ICollectionView
source for sorting, filtering, and navigating. Another useful feature of ICollectio
nView
is grouping. This allows the partitioning of the data into groups based on some criteria (typically a property). Each such group is subject to sorting and/or filtering, if used.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll use the same collection of process objects used previously, but this time we'll group them by some criteria.
Create a new WPF Application named CH06.GroupingData.
Open
MainWindow.xaml
. Add aListBox
to the existing grid, with a simple data template to display information on process objects:<ListBox ItemsSource="{Binding}" HorizontalContentAlignment="Stretch"> <ListBox.ItemTemplate> <DataTemplate> <UniformGrid Rows="1" Columns="2"> <TextBlock Text="{Binding ProcessName}" /> <TextBlock Text="{Binding Id...