Thursday 21 August 2014

ObservableCollection and INotifyPropertyChanged in silverlight

INotifyPropertyChanged:


To allow changes made in the data source to reflect immediately on the target. How is this possible? This is possible by implementing the INotifyPropertyChanged interface. It is a descendent of ObservableCollection<T>, and the interface is implemented for you. What you need to do is take the namespace System.ComponentModel to implement INotifyPropertyChanged interface.  This has the single method called PropertyChanged(). When setting a property value, you need to call the OnPropertyChanged() method if any value changes.

ObservableCollection
To provide notifications for collection changes (new item added, removed, or entire list refreshed), we need to inherit our collection object from ObservableCollection<T>. Add a reference to System.Collections.ObjectModelbefore using ObservableCollection.
Silverlight provides the ObservableCollection<T> class, which is a base class data collection that implements the INotifyCollectionChanged interface, as well as the INotifyPropertyChanged interface. It also has the expected collection support, defined by deriving from the Collection<T> class.

ObservableCollection is a generic dynamic data collection that provides notifications when items get added, removed, or when the whole list is refreshed and INotifyPropertyChanged provides PropertyChanged notification to clients when any property value gets changed.

No comments:

Post a Comment