.Net Event on Collection Update
Is there a collection class of 开发者_如何转开发type IList or IEnumerable that has a flag I can check or event that can be triggered if the collection changes either by add, remove or update?
You're looking for ObservableCollection<T>
. It implements INotifyCollectionChanged
so you can implement that yourself or use/subclass ObservableCollection<T>
.
Yes : ObservableCollection<T>
.
Actually, it implements the INotifyCollectionChanged
interface that defines the CollectionChanged
event (that means you can add the logic to any of your class if ObservableCollection<T>
is not applicable.
There is an ObservableCollection<T>
class in .Net 3.0-4.0 that exposes a CollectionChanged
event which would work for what you want.
精彩评论