在 Windows 8 中过滤 GridView [英] Filtering a GridView in Windows 8

查看:20
本文介绍了在 Windows 8 中过滤 GridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个 GridView,其中 ItemsSource 设置为 ObservableCollection.对底层数据的更新反映在 UI 中,我无需付出任何努力.一切正常.

I currently have a GridView where the ItemsSource is set to an ObservableCollection. Updates to the underlying data are reflected in the UI without any effort on my part. Things are working well.

将过滤器应用于 ObservableCollection 以便仅显示某些项目的最简洁方法是什么?理想情况下,我不想从 ObservableCollection 中实际删除项目,也不想维护两个不同的集合,因为它会使保持同步更具挑战性.CollectionViewSource 看起来很有前途,但 Windows Store 应用程序实现似乎缺乏过滤功能(为什么是 MS????).

What is the cleanest way to apply a filter to the ObservableCollection so that only certain items are displayed? Ideally I don't want to actually remove items from the ObservableCollection, nor do I want to maintain two distinct collections because it will make keeping things in sync more challenging. CollectionViewSource looked promising but the Windows Store App implementation seems to lack the filtering capability (why MS????).

推荐答案

我刚刚在我自己的 C# + XAML Windows 8 应用程序中处理了同样的问题.这三个开源项目中的任何一个都会为您提供您所追求的功能:Bindable LINQObtics连续 LINQ.

I just got done dealing with this same problem in my own C# + XAML Windows 8 app. Any of these three open-source projects will give you the functionality you're after: Bindable LINQ, Obtics, and Continuous LINQ.

CollectionViewSource 不包含 Windows 8 中的过滤功能也同样好,因为无论如何最好将此类功能放入视图模型中.这样做的主要优点是,打包为可移植类库 (PCL),您的视图模型(包括过滤)将可以在您的 WPF、Silverlight 和 Windows 8 项目之间移植.

It's just as well that CollectionViewSource doesn't include the filtering functionality in Windows 8, since it's preferable to put such functionality into the View Model anyway. The main advantage of doing so is that, packaged as a Portable Class Library (PCL), your View Model (including filtering) will then be portable across your WPF, Silverlight, and Windows 8 projects.

虽然以上三个开源项目对我来说看起来很有趣,但我通过构建自己的MVVM 框架.我的框架已经支持排序,所以过滤是一个很自然的补充.使用 Reactive API 我上个月实施的.我还没有上传包含过滤的 MVVM 框架的最新版本.如果以上三个开源项目都不适合您,请告诉我,以便我可以尽快上传.

Although the above three open source projects looked interesting to me, I accomplished this task by building on top of my own MVVM framework. My framework already supports sorting, so filtering was a natural addition. Adding it in was easy while using the Reactive API that I implemented last month. I haven't yet uploaded my MVVM framework's latest version that includes the filtering. Let me know if none of the above three open source projects suit you, so I can get around to uploading a bit sooner.

这篇关于在 Windows 8 中过滤 GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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