Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class NotifiableCollection<T> : Collection<T>, INotifyCollectionChanged
- {
- public NotifiableCollection() { }
- protected override void InsertItem(int index, T item)
- {
- base.InsertItem(index, item);
- OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
- }
- protected override void RemoveItem(int index)
- {
- T item = base[index];
- base.RemoveItem(index);
- OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, item));
- }
- protected override void ClearItems()
- {
- base.ClearItems();
- OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
- }
- public void Move(int oldIndex, int newIndex)
- {
- T item = base[oldIndex];
- base.SetItem(newIndex, item);
- OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Move,
- item, newIndex, oldIndex));
- }
- protected override void SetItem(int index, T item)
- {
- T oldValue = base[index];
- base.SetItem(index, item);
- OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Replace,
- item, oldValue));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement