我定义了一个CollectionViewSource
这样的,但似乎过滤器不起作用。
CollectionViewSource cvs = new CollectionViewSource();
//oc IS AN OBSERVABLE COLLECTION WITH SOME ITEMS OF TYPE MyClass
cvs.Source = oc;
//IsSelected IS A bool? PROPERTY OF THE MyClass
cvs.View.Filter = new Predicate<object>(input=>(input as MyClass).IsSelected == true);
//Major IS AN string PROPERTY OF THE MyClass
cvs.SortDescriptions.Add(new SortDescription(
"Major", ListSortDirection.Ascending));
但是我以这种方式更改了代码,一切都解决了!
CollectionViewSource cvs = new CollectionViewSource();
cvs.Source = oc;
cvs.SortDescriptions.Add(new SortDescription(
"Major", ListSortDirection.Ascending));
cvs.View.Filter = new Predicate<object>(input=>(input as MyClass).IsSelected == true);
有人知道方法吗?