当使用的ObservableCollection< T&GT ;,我还需要实现INotifyPropertyChanged的T类型?我还、类型、LT、ObservableCollection

2023-09-03 16:26:44 作者:﹃阵刺心的痛

为的ObservableCollection< T> 注意事项:

The MSDN reference page for ObservableCollection<T> notes:

https://msdn.microsoft.com/en-us/library/ms743643(v=vs.100).aspx相对=在您的收藏必须满足在的绑定源概述。特别是,如果你使用的单向或的双向(例如,你希望你的UI更新,当源属性动态改变),则必须实现一个合适的属性更改通知机制,如 INotifyPropertyChanged的的接口。

"The objects in your collection must satisfy the requirements described in the Binding Sources Overview. In particular, if you are using OneWay or TwoWay (for example, you want your UI to update when the source properties change dynamically), you must implement a suitable property changed notification mechanism such as the INotifyPropertyChanged interface."

由于的ObservableCollection&LT; T&GT; 已经实现了 INotifyPropertyChanged的,为什么我需要再次实施 INotifyPropertyChanged的 T 也?

Since ObservableCollection<T> already implements INotifyPropertyChanged, why do I need to again implement INotifyPropertyChanged on T also?

推荐答案

考虑您观察到的集合作为数据源的表。从收集的每个对象占用一行,并显示在跨多个列的表

Consider your observable collection as a data source for a table. Each object from the collection occupies one row, and is displayed in the table across multiple columns.

的视图(即你表)需要知道何时修改每个细胞响应于改变对象的属性,而且还响应于添加和删除对象和从集合

The view (i.e. your table) needs to know when to modify each cell in response to changing properties of objects, but also in response to adding and removing objects to and from the collection.

您观察到的领取应付照顾的表行的:它会通知它的观察者,当一个对象被插入,删除,移动等。但是,它缺乏一个什么样的个别对象回事知识,所以它是没有帮助在处理的表中的列的。

Your observable collection takes care of dealing with table rows: it notifies its observers when an object gets inserted, removed, moved, and so on. However, it lacks knowledge of what's going on with individual objects, so it is of no help in dealing with table columns.

这是你的对象有:通过实施 INotifyPropertyChanged的,他们让你的表管理中的列中的数据。

This is where your objects come in: by implementing INotifyPropertyChanged they let your table manage the data in the columns.