Datagrid:没有排序事件吗? [英] Datagrid : Is there no Sorted event?
本文介绍了Datagrid:没有排序事件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道用户何时对 WPF Datagrid 进行了排序。为什么没有排序
事件?我只能找到一个排序事件。
I need to know when a WPF Datagrid has been sorted by the user. Why is there no Sorted
event? I can only find a Sorting event.
我还调查了 CollectionView
和 ListCollectionView
会将对象暴露给View,没有任何运气。
I also investigated the CollectionView
and ListCollectionView
that is exposing the objects to the View, without any luck.
我很惊讶,因为它应该开箱即用。
有任何想法吗?
I am quite surprised as this should come out of the box. Any ideas?
推荐答案
datagrid具有正在排序事件,请订阅!
datagrid has "Sorting" event, subscribe to it!
XAML:
<DataGrid ItemsSource="{Binding YourItems}" AutoGenerateColumns="True" anUserSortColumns="True"
Sorting="DataGrid_Sorting"/>
.cs代码:
private void DataGrid_Sorting(object sender, System.Windows.Controls.DataGridSortingEventArgs e)
{
Console.WriteLine(string.Format("sorting grid by '{0}' column in {1} order", e.Column.SortMemberPath, e.Column.SortDirection));
}
这篇关于Datagrid:没有排序事件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文