用于Caliburn.Micro的WPF DataGrid过滤(WPF DataGrid filtering for Caliburn.Micro)

编程入门 行业动态 更新时间:2024-10-19 15:28:25
用于Caliburn.Micro的WPF DataGrid过滤(WPF DataGrid filtering for Caliburn.Micro)

我有一个使用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.

更多推荐

本文发布于:2023-08-06 03:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444534.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Micro   Caliburn   WPF   filtering   DataGrid

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!