CollectionChangedHandler<TItem, TCollection>
References- DataStoreChangedHandler<TItem, TCollection>
- EnumerableChangedHandler<TItem, TCollection>
- EnumerableChangedHandler<TItem>
Class to help implement collection changed events on a data store
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. This is a simple helper that is much easier to implement than handling the INotifyCollectionChanged.CollectionChanged event directly.
Type parameters:
| TItem | Type of the items in the collection |
| TCollection | Type of the collection where class |
Properties
Methods
AddItem
#public abstract void AddItem(TItem item)
Adds the item to the end of the collection
Parameters:
| item (TItem) | Item to add to the collection |
AddRange
#Adds multiple items to the end of the collection
Remarks: This simply calls 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.
Parameters:
| items (IEnumerable<TItem>) | Enumeration of items to add to the end of the collection |
protected virtual void BeginUpdates()
Called before any methods to change the collection have been called.
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, EndUpdates() is called to signal that they are done.
See Also: EndUpdates()
ElementAt
#Gets the element at the specified index of the current registered collection.
Parameters:
| index (int) | Index of the item to get. |
Returns: The item at the specified index.
protected virtual void EndUpdates()
Called after any methods to change the collection have been called.
IndexOf
#Gets the index of the specified item
Parameters:
| item (TItem) | Item to find the index of |
Returns: Index of the item if contained in the collection, otherwise -1
InsertItem
#Inserts an item at the specified index in the collection
Parameters:
| index (int) | Index to insert the item to |
| item (TItem) | Item to insert |
InsertRange
#Inserts multiple items to the specified index in the collection
Remarks: This simply calls 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.
Parameters:
| index (int) | Index to start adding the items |
| items (IEnumerable<TItem>) | Enumeration of items to add |
InternalElementAt
#Gets the element at the specified index.
Remarks: Derived classes should implement this to get the item at the specified index.
Parameters:
| index (int) | Index of the item to get. |
Returns: The item at the specified index.
InternalIndexOf
#Gets the index of the item from the collection
Remarks: Derived classes should implement this to get the index of the item.
Parameters:
| item (TItem) | Item to find the index |
Returns: index of the item in the collection, or -1 if the item is not found
Register
#Registers a specific collection to observe
Parameters:
| collection (TCollection) | collection to observe |
Returns: true if the collection was registered, false otherwise
RemoveItem
#public virtual void RemoveItem(TItem item)
Removes the specified item
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.
Parameters:
| item (TItem) | Item to remove from the collection |
RemoveRange
#Removes the specified items from the collection
Remarks: This simply calls 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.
Parameters:
| items (IEnumerable<TItem>) | List of items to remove |
RemoveRange
#Removes a specified count of items from the collection starting at the specified index
Remarks: This simply calls 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.
Replaces the item at the specified index
Remarks: This by default will remove then insert the item at the specified index.
Parameters:
| index (int) | Index of the item to replace |
| newItem (TItem) | New item |
Replaces a range of items starting at the specified index.
Remarks: By default this calls ReplaceItem(int, TItem) for each item.
Parameters:
| 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
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.