EnumerableChangedHandler<TItem, TCollection>

CollectionChangedHandler<2>References
public abstract class EnumerableChangedHandler<TItem, TCollection> : CollectionChangedHandler<TItem, TCollection>
Helper class to handle collection change events of an IEnumerable
Remarks: This is used for the platform handler of controls that use collections. This class helps detect changes to a collection so that the appropriate action can be taken to update the UI with the changes. Use this class as a base when you only have an IEnumerable. If the object also implements INotifyCollectionChanged it will get changed events otherwise you must register a new collection each time.
TItemType of each item in the enumerable
TCollectionType of the collection to handle the change events for where class, IEnumerable<TItem>

Properties

Count

#
public override int Count { get; }
Gets the count of the items in the current registered collection.

Methods

AddItem

public abstract void AddItem(TItem item)
Adds the item to the end of the collection
inherited fromCollectionChangedHandler<TItem, TCollection>

AddRange

public virtual void AddRange(IEnumerable<TItem> items)
Adds multiple items to the end of the collection
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: This simply calls CollectionChangedHandler<TItem, TCollection>.AddItem(TItem) for each item in the list. If there is a faster mechanism for doing so, implementors should override this method. For example, sometimes adding a single item will update the UI for each item, this should be overridden so the UI is updated after all items have been added.
items (IEnumerable<TItem>)Enumeration of items to add to the end of the collection

BeginUpdates

protected virtual void BeginUpdates()
Called before any methods to change the collection have been called.
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: There may be multiple methods called when the collection changes, such as RemoveRange then AddRange or RemoveItem then InsertItem. When this happens, some platforms may need to know all of the changes before refreshing the view. After all of the update methods, CollectionChangedHandler<TItem, TCollection>.EndUpdates() is called to signal that they are done.

ElementAt

public virtual TItem ElementAt(int index)
Gets the element at the specified index of the current registered collection.
inherited fromCollectionChangedHandler<TItem, TCollection>
index (int)Index of the item to get.
The item at the specified index.

IndexOf

public virtual int IndexOf(TItem item)
Gets the index of the specified item
inherited fromCollectionChangedHandler<TItem, TCollection>
item (TItem)Item to find the index of
Index of the item if contained in the collection, otherwise -1

InitializeCollection

#
protected virtual void InitializeCollection()
Initializes the collection, usually by adding the collection to the underlying handler.

InsertItem

public abstract void InsertItem(int index, TItem item)
Inserts an item at the specified index in the collection
inherited fromCollectionChangedHandler<TItem, TCollection>

InsertRange

public virtual void InsertRange(int index, IEnumerable<TItem> items)
Inserts multiple items to the specified index in the collection
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: This simply calls CollectionChangedHandler<TItem, TCollection>.InsertItem(int, TItem) for each item in the list. If there is a faster mechanism for doing so, implementors should override this method. For example, sometimes inserting a single item will update the UI for each item, this should be overridden so the UI is updated after all items have been inserted.
index (int)Index to start adding the items
items (IEnumerable<TItem>)Enumeration of items to add

InternalElementAt

#
protected override TItem InternalElementAt(int index)
Gets the element at the specified index.
Remarks: Derived classes should implement this to get the item at the specified index.
index (int)Index of the item to get.
The item at the specified index.

InternalIndexOf

#
protected override int InternalIndexOf(TItem item)
Implements the mechanism for finding the index of an item (the slow way)
Remarks: If the collection object implements IList, this will not get called as it will call it's method of getting the index. This is used as a fallback.
item (TItem)Item to find in the collection
Index of the item, or -1 if not found

OnRegisterCollection

#
protected override void OnRegisterCollection(EventArgs e)
Called when the collection is registered

OnUnregisterCollection

protected virtual void OnUnregisterCollection(EventArgs e)
Called when the object has unregistered the collection
inherited fromCollectionChangedHandler<TItem, TCollection>

Register

public virtual bool Register(TCollection collection)
Registers a specific collection to observe
inherited fromCollectionChangedHandler<TItem, TCollection>
collection (TCollection)collection to observe
true if the collection was registered, false otherwise

RemoveItem

public abstract void RemoveItem(int index)
Removes the item at the specified index
inherited fromCollectionChangedHandler<TItem, TCollection>

RemoveItem

public virtual void RemoveItem(TItem item)
Removes the specified item
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: This will remove the item by finding the index and removing based on index. Implementors should override this method if there is a faster mechanism to do so.
item (TItem)Item to remove from the collection

RemoveRange

public virtual void RemoveRange(IEnumerable<TItem> items)
Removes the specified items from the collection
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: This simply calls CollectionChangedHandler<TItem, TCollection>.RemoveItem(TItem) for each item to remove. If there is a faster mechanism for doing so, implementors should override this method. For example, sometimes removing a single item will update the UI for each item, this should be overridden so the UI is updated after all items have been removed.
items (IEnumerable<TItem>)List of items to remove

RemoveRange

public virtual void RemoveRange(int index, int count)
Removes a specified count of items from the collection starting at the specified index
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: This simply calls CollectionChangedHandler<TItem, TCollection>.RemoveItem(int) for each item to remove. If there is a faster mechanism for doing so, implementors should override this method. For example, sometimes removing a single item will update the UI for each item, this should be overridden so the UI is updated after all items have been removed.
index (int)Index to start removing the items from
count (int)Number of items to remove

ReplaceItem

public virtual void ReplaceItem(int index, TItem newItem)
Replaces the item at the specified index
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: This by default will remove then insert the item at the specified index.
index (int)Index of the item to replace
newItem (TItem)New item

ReplaceRange

public virtual void ReplaceRange(int index, IEnumerable<TItem> newItems)
Replaces a range of items starting at the specified index.
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: By default this calls CollectionChangedHandler<TItem, TCollection>.ReplaceItem(int, TItem) for each item.
index (int)Index of the start of the range
newItems (IEnumerable<TItem>)New items to replace the existing items at the same indexes

Reset

public virtual void Reset()
Resets the collection when it is dramatically changed
inherited fromCollectionChangedHandler<TItem, TCollection>
Remarks: By default this removes all items and adds all items back (if Collection is an IEnumerable{T}) Platform implementations can override this to do something more efficient if needed.