Tuesday, 24 May 2011

Dependency Objects vs INotifyPropertyChanged

WPF and Silverlight user interfaces are all about data binding. 

To allow your POCO (plain old CLR objects) to take advantage of two way data binding, your object needs to raise the change event.  This can be done by either specialising from DependencyObject or by implementing the INotifyPropertyChanged interface.

Here is a simple example of both in action.



You can then bind your UI controls to your objects by setting the DataContext and ItemsSource of the control:

Now you may have noticed I’ve added some validation for the Age property.  In my next blog article I’ll show why I find INotifyPropertyChanged a more flexible solution and gives the ability for contextual validation.

1 comment:

  1. Most of WPF controls derive from DependencyObject. For support binding and thred model but differrent purpose of usage. If we create custom control some time DependencyObject does not enought we should use INotifyPropertyChanged too.