[UWP]如何使用主动排序和过滤获取ListView [英] [UWP] How do I get a ListView with active sorting and filtering

查看:74
本文介绍了[UWP]如何使用主动排序和过滤获取ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个ObservableCollection视图,它允许以动态/实时方式进行排序和过滤。
我看到的是简单的过滤和排序,其中重新运行LINQ查询并创建和显示新的集合。这不是我想要的。我希望视图对底层ObservableCollection中的任何更改作出反应,或者更改为
排序或过滤器。

I need a view into an ObservableCollection that permits sorting and filtering in a dynamic/live way. What I see is simple filtering and sorting where a LINQ query is re-run and a new collection is created and displayed. This is not what I want. I want the view to react to any changes in the underlying ObservableCollection, or changes to the sort or filter.

- 随着项目的添加,删除或更新在底层的ObservableCollection中,视图根据当前设置的任何过滤器和排序动态更新。即,当从ObservableCollection中添加或删除项目时,它们相应地在视图中添加或删除
,以适合筛选和选择的排序。

- As items are added, removed or updated in the underlying ObservableCollection, the view is dynamically updated according to whatever filter and sort are currently set. I.e as items are added or removed from the ObservableCollection they are correspondingly added or removed form the view as appropriate to the filter and sort selected.

- 如果过滤器已更改,从视图中添加或删除项目以使其符合规定...不是批发替换该集合。

- If the filter is changed, items are added or removed from the view to bring it in compliance ... NOT a wholesale replacement of the collection.

- 如果排序已更改,则项目将移至新位置...不是批量替换集合。

- If the sort is changed, items are moved to their new position … NOT a wholesale replacement of the collection.

- 当视图因任何原因而发生更改时,无论是因为基础ObservableCollection更改,还是排序或过滤器更改,那么任何显示视图的ListView如果当前项目仍然存在,则保持当前项目的选择,或保持滚动位置
相对于最初选择它的最近邻居(如果它仍然存在于视图中)。

- When the view changes for any reason, either because the underlying ObservableCollection changes, or the sort or filter changes, then any ListView that is displaying the view keeps the current item selected if it still exists, or keeps the scroll position relative to whatever the originally selected it's closest neighbor would have been if it still existed in the view.

有解决办法吗?

推荐答案

根据您的要求您可能需要创建一个实现INotifyPropertyChanged接口的自定义ObservableCollection类。该类还应对应于过滤器或排序操作。处理类中的事件,更改
源并调用prpertychange事件以通知UI布局。 

Based on your requirement, you might need to create a customized ObservableCollection class which implement INotifyPropertyChanged interface. The class should also correspond to the filter or sorting action. Handle the events inside the class, change the source and call prpertychange event to notify the UI Layout. 

好吧,目前我发现了一些关于此的博客。您可以打开搜索引擎并搜索"过滤和分类UWP中的LISTVIEW - 第2部分 - 代码"。你可以找到一些关于这样做的博客。

Well, currently I found some blogs about this. You could open your search engine and search for "FILTERING AND SORTING A LISTVIEW IN A UWP – PART 2 – THE CODE". You could find some blog about doing this.

祝你好运,

Roy


这篇关于[UWP]如何使用主动排序和过滤获取ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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