Generic collections & dictionary classes with events
Implementing Document-View pattern I faced the problem: standard generic collections and dictionaries (List<T>
, HashSet<T>
for example) don't provide events for modification (OnBeforeAdd, OnAfterAdd, OnRemove, Freeze/Unfreeze methods... )
I suppose events were not implemented for optimization purposes but I have to use and listen for such events using Document class.
I searched Inet for a while and found some demo implementations for lists. Is t开发者_开发技巧here well-known production-proved library with complete set of eventable generic collections/dictionaries or shall I implement such collections by myself?
Thank you in advance!
Have you considered System.Collections.ObjectModel.ObservableCollection<T>
?
From MSDN:
Represents a dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed.
I see this type of collection is used a lot in WPF and Silverlight for it's ability to raise events when data in the collection changes. This allows for rich databinding where the UI is updated based on the events raised by ObservableCollection<T>
.
you can wrap container to your own class and add events to that class.
精彩评论