如何对使用MultiBinding Converter的DataGridTextColumn进行排序 [英] How to Sort a DataGridTextColumn which uses a MultiBinding Converter

查看:272
本文介绍了如何对使用MultiBinding Converter的DataGridTextColumn进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用带有值转换器的多线程来提供我的 DataContext 中的项目集合的可视化显示。这是XAML的一个片段;

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>

SortMemberPath 上的绑定是这样的我可以通过我的 DataContext 中的属性排序。但是,在输出窗口中出现错误

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.

使用 DXGrid by DevExpress ,但不是使用标准的WPF数据网格。有没有人知道为数据网格列提供排序的正确方法?

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">

ie。不要使用绑定,只需直接指定属性名称。

i.e. don't use a binding, just specify the property name directly.

这篇关于如何对使用MultiBinding Converter的DataGridTextColumn进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆