Notify Collection Changed Event Args Reference
I end up using INotifyCollectionChanged
frequently, but not frequently enough to reliably recall how NotifyCollectionChangedEventArgs
works when it is raised from the INotifyCollectionChanged.CollectionChanged
event. There's a nice post by Stephen Cleary that summarizes how this works, but I wanted to take a minute to try to improve the formatting.
Add
The Action
is NotifyCollectionChangedAction.Add
when items are added to the collection.
Property | Description |
---|---|
NewItems |
Contains any items that were added. |
NewStartingIndex |
Index where new items were added, otherwise -1 . |
Remove
The Action
is NotifyCollectionChangedAction.Remove
when items are removed from the collection.
Property | Description |
---|---|
OldItems |
Contains any items that were removed. |
OldStartingIndex |
Index where where items were removed, otherwise -1 . |
Replace
The Action
is NotifyCollectionChangedAction.Replace
when old items are replaced with new items.
Property | Description |
---|---|
NewItems |
Contains items that are replacing old items. |
NewStartingIndex |
Equal to OldStartingIndex . |
OldItems |
Contains the items that were replaced by new items. |
OldStartingIndex |
Contains the index from which the old items were removed. |
Move
The Action
is NotifyCollectionChangedAction.Move
when one or more items are moved within the collection. This operation is logically treated as a Remove
followed by an Add
, so NewStartIndex
is interpreted as though the items had already been removed.
Property | Description |
---|---|
NewItems |
SequenceEqual to OldItems , though they may be different instances. |
NewStartingIndex |
Contains the index to which the items were moved. |
OldItems |
Contains the items that were moved. |
OldStartingIndex |
Contains the index from which the items were moved. |
Reset
The Action
is NotifyCollectionChangedAction.Reset
when a collection is completely reset. None of the properties in the event args will have values.