您可以直接在数据源上做个过滤
https://stackoverflow.com/questions/9615891/filter-an-observable-collection
Bind your ListView
directly
to the filtered collection instead of the ObservableCollection by creating a property -
public ICollectionView YourFilteredCollection
{
get
{
var source = CollectionViewSource.GetDefaultView(collection.Collection);
source.Filter = p => Filter((ProjectViewModel)p);
return source;
}
}
So, now simply you need to call Refresh() on your collection on your check boxes state changed event like this -
YourFilteredCollection.Refresh();
To refresh the collection based on any state change in the item class, you can generalize it by hooking the PropertyChanged
event
of your item class (for this your class need to implement INotifyPropertyChanged) and from there you can call refresh like this -
foreach (YourClass item in collection.Collection)
{
item.PropertyChanged += new PropertyChangedEventHandler(item_PropertyChanged);
}
void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
YourFilteredCollection.Refresh();
}
So, whenever any property changes in your item class, your collection will be filtered.
专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms