I have a grouped WPF DataGrid (the standard Microsoft one) representing some data on the UI for our users.
In order to show totals within the grouped regions, we are overriding the GroupItem DataTemplate as follows in XAML:
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Border BorderBrush="DarkGray" BorderThickness="1" Padding="12,0">
<Expander VerticalContentAlignment="Center" IsExpanded="{Binding ., Converter={Converters:ExpandedGroupConverter}}" ExpandDirection="Up">
<Expander.Header>
<Canvas>
**<TextBlock Text="{Binding} />**
</Canvas>
</Expander.Header>
<ItemsPresenter/>
</Expander>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
At runtime, currently, the TextBlock text binds to the DataContext, which is a CollectionViewGroup, which makes sense as the grid is binding to a CollectionView wrapping our datasource.
However, the CollectionViewGroup is very limited and does not give us access to its containing ViewModel, where we are storing properties such where to position groups (we're gathering coordinates from the columns when we first layout the grid), and need to bind to them, so that we can, for example, show a total directly above/below given column in a group.
In a nutshell we're trying to access more than just the CollectionView object from within a DataTemplate that targets a GroupItem. Any input on how to do this (or if there is a better approach to get summed totals per columns to show in group total templates) appreciated.
EDIT: So far, a workaround is to have a "Parent ViewModel" property on our items, although this bloats the model, I wish there was a more direct way to do this.