- How to explain DependencyProperty using real world analogy?
- Why is it needed?
I like Dave's answer, but I will say that this is how I usually think about DependencyProperties, at least with Silverlight (I think WPF is similar):
- If you want to create something that can be target of a binding, you want to create a class that implements INotifyPropertyChanged.
- If you want to create something that you can define in XAML and be bound to something, you want to create a derivative of DependencyObject with DependencyProperties.
Gaining that understanding was a turning point in my ability to design things in Silverlight appropriately.
From an answer to my post on StackOverflow by Kent Boogart:
In order for a property to be the target of a binding, that property must be a dependency property. WPF (and Silverlight) use dependency properties as a means for tracking changes, supporting value precedence (for animations and the like), and a bunch of other useful things. Note that I said "target". The source of a binding can be any old object that supports change notification.
This small tidbit of knowledge has really helped me out. So use it if you want to databind to properties in your custom UserControls.
For a real-world analogy, I guess I would go with a Phone Book entry.
There are lots of people/phone numbers in the world, but to be found by everyone you post your number in the phone book.
Likewise, there are many regular properties that exist, and items that are aware of them know they exist and can use them, but a DependencyProperty is something that the entire application is aware of and can lookup when needed.