Choosing the right property type in Silverlight

If you are going to be creating your own classes or controls in Silverlight, you need to choose wisely when you implement the properties for your new class or control.

Silverlight properties can be either:

  1. Standard CLR Properties
  2. Standard CLR Properties that raise the INotifyPropertyChanged interfaces PropertyChanged event
  3. DependecyProperty instances that support a value precedence based on animation, data binding, templates, styles, and default values.

The kind of property you need to create depends a great deal on what you need to do with it. 

If you just need a place to hold onto a value, a standard CLR property will suffice. 

If you only need to provide a value in data binding, then INotifyPropertyChanged is probably the right choice.  This is the simplest way to provide value change notification to subscribers.  DependencyProperties also provide change notification, but at a much higher cost, and if all you need is the change notification piece then the DependencyProperty comes with too much extra baggage.

If you need the property to be the target of an animation or data binding, or if you want to set it’s value in a template or style, then you should implement it as a DependencyProperty. 

Property Type Choice Flow Chart

Do you have a different opinion on the above?  Tell me about it!

Leave a Reply