Ejemplo n.º 1
0
        protected override void RemoveItem(int index)
        {
            T item = this[index];

            if (item is INotifyPropertyChanged notify)
            {
                notify.PropertyChanged -= Item_PropertyChanged;
            }

            base.RemoveItem(index);

            Removed?.Invoke(this, new SingleChangeEventArgs <T>(index, item, SingleChangeType.Removed));
            RemovedAny?.Invoke(this, new SingleChangeEventArgs <T>(index, item, SingleChangeType.Removed));
        }
Ejemplo n.º 2
0
        protected override void SetItem(int index, T newItem)
        {
            T oldItem = this[index];

            if (oldItem is INotifyPropertyChanged oldNotify)
            {
                oldNotify.PropertyChanged -= Item_PropertyChanged;
            }

            base.SetItem(index, newItem);
            Set?.Invoke(this, new SetItemEventArgs <T>(index, oldItem, newItem));

            if (newItem is INotifyPropertyChanged newNotify)
            {
                newNotify.PropertyChanged += Item_PropertyChanged;
            }

            RemovedAny?.Invoke(this, new SingleChangeEventArgs <T>(index, oldItem, SingleChangeType.Removed));
            AddedAny?.Invoke(this, new SingleChangeEventArgs <T>(index, newItem, SingleChangeType.Added));
        }
Ejemplo n.º 3
0
        protected override void ClearItems()
        {
            T[] items = new T[Count];
            for (int i = 0; i < Count; i++)
            {
                if (items[i] is INotifyPropertyChanged notify)
                {
                    notify.PropertyChanged -= Item_PropertyChanged;
                }

                items[i] = this[i];
            }

            base.ClearItems();

            Cleared?.Invoke(this, new CollectionClearEventArgs <T>(items));

            for (int i = 0; i < items.Length; i++)
            {
                RemovedAny?.Invoke(this, new SingleChangeEventArgs <T>(i, items[i], SingleChangeType.Removed));
            }
        }