tags:

views:

37

answers:

1

Say I have a control that inherits from UserControl (hence one of its super classes is DependencyObject). It's very easy to solve a notification problem using a DependencyProperty, since INotifyPropertyChanged needs a little implementation, and the other option would be creating a method to modify the state of the control (like myControl.HideTextBox()). I guess there are several more options to solve this, but since the control already inherits from DependencyObject, a DependencyProperty seems to be the more obvious way, but it might not be the optimal.

Any thought?

Thanks!

+4  A: 

The real feature of dependency properties isn't that you get change notification for free (though that is there). The real feature is that only dependency properties can be targets of data binding. This is what you should consider first and foremost when deciding whether a property should be dependency or not.

For a control, almost all properties should be bindable, and thus dependency.

Pavel Minaev
So I'm sort of confused. You said the that's not the real feature of the DependencyProperties, but you said that almost all properties should be bindable, hence dependency. Is it good to use them for my example or not?
Carlo
See the second paragraph of my answer. I cannot really say much else unless you tell more about your control and the property, about which you're in doubt. I would also suggest looking at stock WPF controls to see which of their properties are dependency (you'll find that almost all are).
Pavel Minaev