In .Net/WPF, what is a Dependency Property and when should I use it?


I'm a relative newbie to the world of WPF.
I've played a little bit and did a bunch of reading on dependency properties.

I've found and read many articles regarding Dependency Properties on the WEB,
but it still hasn't sunk in.

After all this reading, I'm still not entirely clear on what they REALLY are and when
I should REALLY BE USING them.

What is the relevence of using a PropertyMetaData() object when registering a Dependency Property?

I understand that if I declare a dependency property, then that property is associated
with an instance property on my class. I know that that property is then accessible
through XAML as a tagged element/property (<Property Foo> ... </PropertyFoo>)
rather than as if it were an attribute.

I also (sort of) understand where a dependency property gets stored when registered.

In the simplest terms (in ENGLISH), I'm still struggling with what it REALLY is and when to
use it.

jxbmaSoftware ConsultantAsked:
Who is Participating?
apeterConnect With a Mentor Commented:
When you are create a custom control in WPF control and you want custom properties to be set in XAML then you can go for dependency property.

for want to have a texbox control which accepts only Numeric. This is control is not available straight way.  When you want create a  Custom control for this,  you will use Texbox control for this. Lest consider you want to introduce a "MaxLength" Property for you custom control to be set in XAML, you can make use of Denpendency property.

Internally all xaml properties for any standard controls are dependency properties in WPF. Hope this helps.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.