ObservedCollection<T>
The ObservedCollection is a subclass of ObservableCollection that allows subscribing to changes in the collection. It provides a more fine-grained control over the types of changes that can be subscribed to (e.g. item added, item removed, item updated), as well as the ability to subscribe and unsubscribe to these change notifications.
Usage
Here is an example of using the ObservedCollection
class:
Getting the index of an item
Here is how you can get the index of a changed item:
If you have duplicates in your collections, you might want to use IndexedObservedCollection
instead which will notify subscribers with the index of the item.
Properties
SubscriberCount
: the number of subscribers currently listening for change notifications.
Constructors
ObservedCollection()
: constructs an empty ObservedCollection<T>.
Methods
Subscribe(Action<T, ChangeType> callback)
: subscribes the given callback to be notified of changes to the collection.Unsubscribe(Action<T, ChangeType> callback)
: removes the given callback from the list of subscribers.Clear()
: removes all items from the collection and sends a change notification to all subscribers for each removed item.ClearSubscriptions()
: removes all subscribers from the list of subscribers.
Last updated