יום שני, 11 באפריל 2011

WPF - ObservableCollection via BindingList



Very important question, witch data structure to use when we working with WPF  ObservableCollection or BindingList?

1.      The practical difference is that BindingList is for WinForms, and ObservableCollection is for WPF.
From a WPF perspective, BindingList isnt properly supported, and you would never really use it in a WPF project unless you really had to.

but...

2.      ObservableCollection implements INotifyCollectionChanged which provides notification when the collection is changed (you guessed ^^) It allows the binding engine to update the UI when the ObservableCollection is updated.
However, BindingList implements IBindingList.
IBindingList provides notification on collection changes, but not only this. It provides a whole bunch of functionality which can be used by the UI to provides a lot more thing than only UI updates according to changes, like:
·         Sorting
·         Searching
·         Add through factory (AddNew member function).
·         Readonly list (CanEdit property)
All these functionalities are not available in ObservableCollection
Note that in Silverlight, BindingList is not available as an option: You can however use ObservableCollections and ICollectionView (and IPagedCollectionView if I remember well).

The choice is yours :-)

Thanks.

אין תגובות:

הוסף רשומת תגובה