Implementing a summary header row for a SL DataGrid I cannot find a way to bind to the DataGrids ItemsSource property (and apply an IValueConverter).
When simply specifying Binding the Converter receives the ViewModel as the DataGrids DataContext but I’d rather not couple the ViewModel to my Converter:
<!-- somewhere in my DataGrid ControlTemplate -->
<sdk:DataGridCell Content="{Binding Converter={StaticResource SummaryRow}}" />
I tried to create a RelativeSource, but xaml complains that I cannot use AncestorType in this context:
<sdk:DataGridCell Content="{Binding RelativeSource={RelativeSource FindAncestor AncestorType={x:Type DataGrid}}, Converter={StaticResource SummaryRow}}" />
My DataGrid itself is bound to a CollectionViewSource which handles grouping and sorting.
I already implemented displaying columns sums for DataGridRowGroupHeader using the first approach and the respective Converter receives a CollectionViewGroup from which I can retrieve items without coupling to the ViewModel.
I figured out the correct way to achieve this and pass the
ListCollectionViewbound to the DataGridsItemsSourceto theIValueConverterinside my customizedControlTemplate: