我有一个使用Caliburn.Micro的WPF应用程序。 DataGrid绑定到ViewModel中的对象集合。 您能否建议一种过滤DataGrid内容的方法,如果可能,可以通过任何字段进行过滤?
谢谢。
I have a WPF application using Caliburn.Micro. A DataGrid is bound to a collection of objects in the ViewModel. Could you please suggest a way to filter the DataGrid contents, if possible by any field?
Thanks.
最满意答案
在视图模型中创建一个新的属性:
private ICollectionView fooView; public ICollectionView FooView { get { return this.fooView; } set { this.fooView = value; NotifyPropertyChanged("FooView"); } }然后在填充可绑定集合之后:
// Populate collection BindableCollection collectionName = this.PopulateCollection(); FooView = CollectionViewSource.GetDefaultView(collectionName);在您的视图中,将绑定从collectionName更改为FooView 。
CollectionView类提供了对数据进行排序/过滤/分组的方法。 在你的情况下如何:在视图中过滤数据 。 过滤器代码将根据您的型号和要求而有所不同。
Create a new property in the view-model:
private ICollectionView fooView; public ICollectionView FooView { get { return this.fooView; } set { this.fooView = value; NotifyPropertyChanged("FooView"); } }And then after you populate the bindable collection:
// Populate collection BindableCollection collectionName = this.PopulateCollection(); FooView = CollectionViewSource.GetDefaultView(collectionName);In your view change the binding from collectionName to FooView.
The CollectionView classes provide ways to sort/filter/group the data. In your case How to: Filter Data in a View. The filter code will vary depending on your model and requirements.
更多推荐
发布评论