Filtering a GridView in Windows 8

南楼画角 提交于 2019-12-05 20:43:08

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.

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.

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.

Asuming you're using some kind of MVVM of the templates,using LINQ:

this.DefaultViewModel["GreaterThan10Items"] = originalList.Where(c => c.SomeProperty > 10)
    .Select(c => new {c.SomeProperty, c.OtherProperty});

Or maybe:

this.DefaultViewModel["Children"] = from query in originalList
                                     where query.age <10
                                     select new Person
                                     {
                                      age= query.age,
                                      name = query.Name
                                     };

Of course, the ItemViewSource must be linked to GreaterThan10Items and your GridView binded to that ItemViewSource

You can use my ObservableComputations library. For example if you want bing filtered by specific type orders to GridView:

GridView.ItemsSource = OrdersObservableCollection
    .Filtering(o => o.Type == OrdersFilter.SelectedType)

Now GridView is automatically refreshed when OrdersObservableCollection changes or Order.Type property changes. Ensure Oreder class implements INotifyPropertyChanged.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!