在列标题单击时使 WPF ListView/GridView 排序的最佳方法? [英] Best way to make WPF ListView/GridView sort on column-header clicking?

查看:32
本文介绍了在列标题单击时使 WPF ListView/GridView 排序的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

互联网上有很多的解决方案试图填补 WPF 这个看似非常基本的遗漏.我真的很困惑什么是最好的"方式.例如...我希望在列标题中有小的向上/向下箭头来指示排序方向.显然有 3 种不同的方法可以做到这一点,一些使用代码,一些使用标记,一些使用标记加代码,而且看起来都像是一个黑客.

There are lots of solutions on the internet attempting to fill this seemingly very-basic omission from WPF. I'm really confused as to what would be the "best" way. For example... I want there to be little up/down arrows in the column header to indicate sort direction. There are apparently like 3 different ways to do this, some using code, some using markup, some using markup-plus-code, and all seeming rather like a hack.

以前有没有人遇到过这个问题,并找到了他们完全满意的解决方案?WPF 中缺少这样一个基本的 WinForms 功能并且需要被黑掉,这似乎很奇怪.

Has anyone run into this problem before, and found a solution they are completely happy with? It seems bizarre that such a basic WinForms piece of functionality is missing from WPF and needs to be hacked in.

推荐答案

这完全取决于,如果您使用的是 WPF Toolkit 中的 DataGrid,那么有一个内置排序,甚至是多列排序有用.在此处查看更多信息:

It all depends really, if you're using the DataGrid from the WPF Toolkit then there is a built in sort, even a multi-column sort which is very useful. Check more out here:

Vincent Sibals博客

或者,如果您使用的是不支持排序的其他控件,我建议您使用以下方法:

Alternatively, if you're using a different control that doesn't support sorting, i'd recommend the following methods:

李高的自定义排序

关注:

李高的更快的排序

这篇关于在列标题单击时使 WPF ListView/GridView 排序的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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