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

Hi:

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.

Thanks,
JohnB
LVL 1
jxbmaSoftware ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aaron JabamaniTechnical ArchitectCommented:
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 example...you 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.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.