Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Binding ObservableCollection是如何工作的?_Binding_Observablecollection - Fatal编程技术网

Binding ObservableCollection是如何工作的?

Binding ObservableCollection是如何工作的?,binding,observablecollection,Binding,Observablecollection,我正在查看ObservableCollection代码(多亏了awsome.NET Reflector),惊讶地发现Add和Remove方法没有被覆盖。那么,ObservableCollection如何引发PropertyChanged或CollectionChanged事件,以便在添加或删除某些内容时发出通知?它会覆盖基本集合类的一系列受保护的方法,例如InsertItem(int index,T item)、RemoveItem(int index)等 这些覆盖专门引发事件: protect

我正在查看ObservableCollection代码(多亏了awsome.NET Reflector),惊讶地发现Add和Remove方法没有被覆盖。那么,ObservableCollection如何引发PropertyChanged或CollectionChanged事件,以便在添加或删除某些内容时发出通知?

它会覆盖基本集合类的一系列受保护的方法,例如InsertItem(int index,T item)、RemoveItem(int index)等

这些覆盖专门引发事件:

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方法。