【问题标题】:Removing the sort arrow from DataGrid programmatically in WPF在 WPF 中以编程方式从 DataGrid 中删除排序箭头
【发布时间】:2013-05-13 23:28:35
【问题描述】:

在我的 WPF 应用程序中,我有一个 DataGrid,其中包含一些显示我的可排序数据的列。用户可以对他想要的任何列进行排序和子排序。

我添加了一个按钮,该按钮应该清除排序并使用 MVVM 模式将 DataGrid 返回到未排序状态(这意味着该按钮绑定到 ViewModel 中的 RelayCommand,这会清除 DataGrid 的数据源的 SortDescriptions .)

这就是代码现在的样子:

ViewModelLocator.MyViewModel.GroupedItems.SortDescriptions.Clear();

DataGrid 的DataSourceGroupedItems 对象(类型为ListCollectionView)。当我单击该按钮时,我看到 DataGrid 返回到其原始的未排序状态,但是,列标题中的排序箭头保持不变,就好像 DataGrid 仍在排序一样。如何以编程方式删除这些箭头?

【问题讨论】:

    标签: c# wpf sorting datagrid listcollectionview


    【解决方案1】:

    要删除DataGrid 中的箭头,请尝试:

    foreach (var column in dt.Columns)
    {
        column.SortDirection = null;
    }
    

    其中dtDataGrid

    【讨论】:

    • 谢谢!有没有办法在不知道我的DataGrid 控件的情况下删除它们?
    • 不幸的是,我还没有遇到过这样的事情。我怀疑这是可能的:(
    • 您的意思是应用程序中的所有数据网格控件?如果是这样,您可以遍历控件类型,如果类型是数据网格,那么您可以将上述属性设置为 null !
    • 我想没有办法以编程方式这样做,这很奇怪。谢谢大家的回答
    猜你喜欢
    • 2016-09-30
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 2011-07-21
    • 2011-04-22
    • 2012-10-23
    • 1970-01-01
    相关资源
    最近更新 更多