How to Sort a DataGridTextColumn which uses a MultiBinding Converter

匿名 (未验证) 提交于 2019-12-03 08:52:47

问题:

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?

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!