Monday, March 16, 2009

ObservableDictionary

The existing Dictionary is not a friend of WPF in the case of databinding.ie WPF can't listen on it's CollectionChanged and hence the UI won't get updated if you add or remove anything to or from the dictionary.
What I was doing is to create a new class with 2 properties (Key and Value) and it's Collection class derived from ObservableCollection.

For example in a card game, if we want to store the 'Play' keyed by Player object (like Dictionary<player,card>),we have to create a class PlayCard which have Player and Card properties and it's collection class PlayCardCollection derived from ObservableCollection.

This is very much time consuming.Here Dr.WPF has provided one implementation of ObservableDictionary which has the capabilities to provide CollectionChanged.Now it is very easy to have ObservableDictionary<player,card>.
Thanks to Dr.WPF for such a great work.

No comments:

Post a Comment