views:

71

answers:

2

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 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?

+3  A: 

ObservableCollection<T> - designed specifically for WPF binding.

Aviad P.
While this is true, one shouldn't rely on it. It has some draw backs that make it frustriating at times. If you use it for an OM that you need to use else where, the added dependency on WindowsBase.dll is annoying.
dhopton
ObservableCollection<T> (plus INotifyCollectionChanged and ReadOnlyObservableCollection) have been type forwarded into System.dll for .Net 4 :-)
Jalfp
A: 

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.

dhopton
I'm exposing my properties as concrete collections (e.g. CustomerCollection), not mere interfaces. That means I can change the base class whenever I want at just the cost of a recompile.
Jonathan Allen