我对 wpf 工具包 DataGrid
有疑问。
我有一个包含三列的 ItemsSource
:
名字
姓氏
地址
在 C# 代码隐藏中,我设置了排序方向和要排序的列,如下所示:
ICollectionView view = CollectionViewSource.GetDefaultView(dataGrid1.ItemsSource);
view.SortDescriptions.Clear();
view.SortDescriptions.Add(new SortDescription("LastName", ListSortDirection.Ascending));
view.Refresh();
实际排序没有问题,但标题视觉样式有问题。如果用户通过单击标题对列进行排序,则视觉样式会发生变化,但视觉样式并不表示列排序说明是以编程方式设置的。
为什么会这样,我怎样才能切换标题使其显示为已排序?
最佳答案
我以前没有尝试过,但我认为您可以设置列的 SortDirection 属性。
int columnIndex = 0;
this.dataGrid1.ColumnFromDisplayIndex(columnIndex).SortDirection =
ListSortDirection.Descending;
关于c# - wpf 以编程方式设置排序,以便将标题切换为已排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3343982/