DataStoreChangedHandler<TItem, TCollection>
CollectionChangedHandler<2>public abstract class DataStoreChangedHandler<TItem, TCollection> : CollectionChangedHandler<TItem, TCollection>, IEnumerable<TItem>
Class to help implement change handling for a IDataStore<T>
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 are detecting changes for an IDataStore<T>. If the object also implements INotifyCollectionChanged, it will get changed events. Otherwise, you must register a new collection each time.
Type parameters:
| TItem | Type of items in the data store |
| TCollection | Type of the data store to detect changes on where class, IDataStore<TItem> |
Properties
Collection
public TCollection Collection { get; protected set; }
Gets the collection that this handler is observing
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 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.
Parameters:
| 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.
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
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.
EndUpdates
protected virtual void EndUpdates()
Called after any methods to change the collection have been called.
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 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.
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
#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.
Parameters:
| item (TItem) | Item to find in the collection |
Returns: Index of the item, or -1 if not found
OnUnregisterCollection
Called when the object has unregistered the collection
Register
Registers a specific collection to observe
Parameters:
| collection (TCollection) | collection to observe |
Returns: true if the collection was registered, false otherwise
RemoveAllItems
public abstract void RemoveAllItems()
Removes all items from the collection
Parameters:
| index (int) | Index of the item to remove |
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 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.
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 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.
ReplaceItem
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 |
ReplaceRange
Replaces a range of items starting at the specified index.
Remarks: By default this calls CollectionChangedHandler<TItem, TCollection>.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.
Unregister
public virtual void Unregister()
Unregisters the current registered collection