futurice/windows-app-development-best-practices

Dependency Properties

jarnmo opened this issue · 1 comments

Feel free to comment and discuss Dependency Properties here.

What are they good or bad for? Good practices in using them? What kind of issue have you run into? What are the alternatives?

Any thoughts are welcome!

So, afaik, Dependency Properties are the only way to make properties that can be bound To. My main problems with them are that they require a bit of boiler plate code (although VS 'propdp'-snippet helps a lot), rely on string matching, and the definition is easy to get wrong, in which case you'll only get a runtime exception. There's also no good way to make a dependency property read only, although I'm not even sure there's a situation you'd really need to do that anyway.

Usage wise, I think it's problematic that it's not explicit which properties are Dependency Properties and which are not. You can always check if the DependencyObject has the static [PropertyName]DependencyProperty defined, and at least VS designer let's you know if you try to bind to a property that is not a Dependency Property, but still, doesn't seem ideal to me.

But then again, I'm not aware of an alternative way to implement bindable To properties.