Following this tutorial I had an idea to put in the Expander Header more data.
I have 2 tables (Document 1 – * Entry).
I’m displaying the Entries grouped by Documents and I don’t want some data to be repeated in the
datagrid so I thought to place it in the expander header.
<DataGrid.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Name}" />
</StackPanel>
</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">
<TextBlock Text="{Binding Path=Name}" />
<TextBlock Text=" - "/>
**<TextBlock Text="{Binding Path=Document.Number or Name2}"/>**
</StackPanel>
...
You can do this:
Converter:
Taking first item from collection in group to form header title might not be the most elegant solution but it will serve the purpose.
Full code is available here: ExpanderHeadersInDataGridGroupStyle.zip