Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone tell me clearly about dependency property.
Thanks in advance
Posted

1 solution

All right, you swallowed the pure terminological bait, if you think that dependency property "is always static readonly". Not even close. "Always static" is not a property (which is of course can be static), but the instance of the class StaticProperty, which is — surprise! — is not a property. (Therefore, "readonly property" is just your fantasy.)

This is a static field needed to implement the property, a kind of a property descriptor, which is a real .NET property and, of course, does not have to be static.

You can read original documentation and understand it all: https://msdn.microsoft.com/en-us/library/ms752914%28v=vs.110%29.aspx.

Of course, it requires using your brain's muscles. If you think it's difficult, I can offer you very simplified, extremely short explanation of the idea and the technique of using of this feature, with explanation of the rationale, complete with a shortest possible code sample. Please see just this section of my article: The Problem of Unwanted WPF ProgressBar Animation: a Clearer Solution (3.3. By Virtue of Dependency Property).

The article itself is very insignificant, dedicated to a tiny problem, but the illustration of the dependency property feature is really clear and minimalistic. Of course, my explanation is not comprehensive. For all the detail, please see the first link.

—SA
 
Share this answer
 
v3
Comments
Member 11428367 15-Apr-15 3:31am    
what is purpose of dependency property in wpf and it is working behind?
Sergey Alexandrovich Kryukov 15-Apr-15 3:46am    
This is exactly what I explain in my section of my article referenced: for binging. In code behind, you can change or read the property exactly as another other property. Implementation is different, but the usage does not care of implementation detail, right? You just know that property and read or write it. But how to tell XAML to do the same? XAML is not a person, it just has those attributes. The dependency property is the way to tell about this property by its registered name.

This is the whole point of registration. You need to understand how XAML works (I mean only UI XAML here, for a form or a user control). It is just used during the build. Now, the code of the build task is agnostic. It is supposed to read XAML and generate some, say C# code, having some compiled code of some UI element. But how? Think of it, and you will understand it: you cannot just read the code (or documentation) and see where the property is and what it does. It might not be even available. You tell it to the build task using XAML through registered metadata created when the property is registered.

For other uses, see the MSDN article I referenced first. You will also find further detail. My thing was to give you the idea.

—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900