如何在WPF DataGridColumn上更改第一个排序方向 [英] How to change first sort direction on WPF DataGridColumn

查看:652
本文介绍了如何在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为空时,我将其设置为升序,以便默认排序器将使SortDirection反向降序,这仅在第一个排序中发生,因为这是SortDirection唯一的null。 / p>

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屋!

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