Binding ObservableCollection是如何工作的?
我正在查看ObservableCollection代码(多亏了awsome.NET Reflector),惊讶地发现Add和Remove方法没有被覆盖。那么,ObservableCollection如何引发PropertyChanged或CollectionChanged事件,以便在添加或删除某些内容时发出通知?它会覆盖基本集合类的一系列受保护的方法,例如InsertItem(int index,T item)、RemoveItem(int index)等 这些覆盖专门引发事件:Binding ObservableCollection是如何工作的?,binding,observablecollection,Binding,Observablecollection,我正在查看ObservableCollection代码(多亏了awsome.NET Reflector),惊讶地发现Add和Remove方法没有被覆盖。那么,ObservableCollection如何引发PropertyChanged或CollectionChanged事件,以便在添加或删除某些内容时发出通知?它会覆盖基本集合类的一系列受保护的方法,例如InsertItem(int index,T item)、RemoveItem(int index)等 这些覆盖专门引发事件: protect
protected override void InsertItem(int index, T item)
{
this.CheckReentrancy();
base.InsertItem(index, item);
this.OnPropertyChanged("Count");
this.OnPropertyChanged("Item[]");
this.OnCollectionChanged(NotifyCollectionChangedAction.Add, item, index);
}
哼!谢谢我注意到Collections.InsertItem被重写,但我未能检查名为virtual InsertItem方法的base.Add方法。