I use a multibinding with a value converter to provide the visual display of a collection of items in my DataContext
. Here is a snippet of the XAML;
<DataGrid.Columns>
<DataGridTextColumn x:Name="Column1"
SortMemberPath="{Binding Path=SomeDataModelProperty}">
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource MyCustomConverter}">
<Binding Path="SomeDataModelProperty" />
<Binding RelativeSource="{RelativeSource Self}" Path="ActualWidth" />
<!-- Other bindings -->
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
The binding on the SortMemberPath
is such that I can sort by the property in my DataContext
. However, I get an error on the output window
Cannot find governing FrameworkElement or FrameworkContentElement for target element.
Googling this issue yields a result using DXGrid by DevExpress, but not one using the standard WPF data grid. Does anyone know the correct way to provide the sorting to the data grid column?
I figured it out, thanks to this article. In the end it is quite simple;
<DataGridTextColumn x:Name="Column1"
SortMemberPath="SomeDataModelProperty">
i.e. don't use a binding, just specify the property name directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With