WPF: What is the right base class for collections used in data binding?

Deadly 提交于 2019-12-24 05:55:04

问题


I am building an object model with strongly typed collection classes (e.g. CustomerCollection). I want to support full two-way binding on both the collection itself and all of the data models in the collection.

For the models it seems like implementing INotifyPropertyChanged is the right way to wire up the models. But what inferface/base class should I use so that WPF knows when my collection's contents change?


回答1:


ObservableCollection<T> - designed specifically for WPF binding.




回答2:


I would recommend typing your properties that you expose as IList, or IEnumerable (generic or not, your choice), rather than ObservableCollection since it ties you into that implementation, and there are a number of situations that this becomes annoying.

The specific interface you need your collections to implement is INotifyCollectionChanged.



来源:https://stackoverflow.com/questions/2124072/wpf-what-is-the-right-base-class-for-collections-used-in-data-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!