I am displaying jobs. Jobs got states like this:
public enum JobState
{
Done,
Running,
Overdue,
Disabled
}
DataGrid
State
Name
State
DataContext
GroupItem
RelativeSource
<DataGrid ItemsSource="{Binding Path=JobCollectionView}" [..]>
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=State}" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="True">
<Expander.Header>
<StackPanel Orientation="Horizontal">
//Error is here: <TextBlock Text="{Binding Path=StateDescription}" />
<TextBlock Text="{Binding Path=ItemCount}"/>
<TextBlock Text=" Jobs"/>
</StackPanel>
</Expander.Header>
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</DataGrid.GroupStyle>
The DataContext
of GroupItem
is internal class named CollectionViewGroupInternal
. You already know that number of items is represented by ItemCount
on that class. The rest of the puzzle - name of group is represented by Name
property :) Since that is just enum in your case - you can bind directly to that Name
property (it contains an instance of your JobState enum).