如何更改 WPF DataGridColumn 上的第一个排序方向 [英] How to change first sort direction on WPF DataGridColumn
问题描述
现在(默认)当您单击用户可排序的 DataGridColumn
上的标题时,它会在第一次单击时升序排序,在第二次单击时降序排序.
Right now (default) when you click a header on a user sortable DataGridColumn
it sorts it ascending on first click and descending on second click.
如何让它在第一次点击时降序排序,在第二次点击时升序?
How can I make it sort descending on first click and ascending on second click?
推荐答案
我想出了一个方法,但不确定它是否是最好的方法.但基本上当排序事件触发且当前 SortDirection 为空时,我将其设置为 Ascending,以便默认排序器将 SortDirection 反转为降序,这仅发生在第一次排序中,因为这是 SortDirection 唯一一次为空.
I figured out a way to do it, not sure if it is the best way. But basically when the sorting event triggers and the current SortDirection is null I set it to Ascending so that the default sorter will reverse the SortDirection to descending, and this only happens on the first sort because that is the only time the SortDirection is null.
myGrid.Sorting += (s, e) => e.Column.SortDirection = e.Column.SortDirection ?? ListSortDirection.Ascending;
这篇关于如何更改 WPF DataGridColumn 上的第一个排序方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!