INotifyCollectionChanged 接口

定义

例如,当添加和删除项或清除整个列表时,向侦听器通知动态更改。Notifies listeners of dynamic changes, such as when an item is added and removed or the whole list is cleared.

public interface class INotifyCollectionChanged
public interface INotifyCollectionChanged
type INotifyCollectionChanged = interface
Public Interface INotifyCollectionChanged
派生

注解

可以枚举实现任何集合IEnumerable接口。You can enumerate over any collection that implements the IEnumerable interface. 但是,若要设置动态绑定,以便插入或删除集合中的更新UIUI自动,该集合必须实现INotifyCollectionChanged接口。However, to set up dynamic bindings so that insertions or deletions in the collection update the UIUI automatically, the collection must implement the INotifyCollectionChanged interface. 此接口公开CollectionChanged只要基础集合发生更改,就必须引发的事件。This interface exposes the CollectionChanged event that must be raised whenever the underlying collection changes.

WPFWPF 提供了ObservableCollection<T>类,该类是公开的数据集合的内置实现INotifyCollectionChanged接口。provides the ObservableCollection<T> class, which is a built-in implementation of a data collection that exposes the INotifyCollectionChanged interface. 有关示例,请参见 如何:创建并绑定到 ObservableCollectionFor an example, see How to: Create and Bind to an ObservableCollection.

集合中的个别数据对象必须满足的要求中所述绑定源概述The individual data objects within the collection must satisfy the requirements described in the Binding Sources Overview.

在实现自己的集合之前, 请考虑使用ObservableCollection<T>或一个现有集合类,如List<T>Collection<T>,和BindingList<T>,此外还有许多其他。Before implementing your own collection, consider using ObservableCollection<T> or one of the existing collection classes, such as List<T>, Collection<T>, and BindingList<T>, among many others.

如果有高级的方案,但希望实现自己的集合,请考虑使用IList,它提供的对象,可按照索引单独访问并提供最佳性能的非泛型集合。If you have an advanced scenario and want to implement your own collection, consider using IList, which provides a non-generic collection of objects that can be individually accessed by index and provides the best performance.

事件

CollectionChanged

当集合更改时发生。Occurs when the collection changes.

适用于

另请参阅