Dependency properties are created the same way as properties.
Is a dependency property used only while creating a custom control?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Dependency property is a property (not itself, but dependent on another, let’s say a XAML Binding property) which register another property.
The dependecy property register the other binding property in the code behind by registering it. A example that is used in my project is as follows:
In the above code the ImageUri, is a dependency property which register the Source, that is defined/declared inside generic.xaml (whatever not sure whether declared, defined or anything else) as follows:
So here it is quite important that the template binding value in the XAML should be registered as dependency property in the code behind.
So when we have defined in XAML that the Image Source should be template bind with Source, we have registered the same Source
As a DependencyProperty.
We have to say which type of dependency property is that, in above example the Source is the type of BitmapImage, so we have defined typeof(BitmapImage).
Now the owner/parent of this dependency property is our customControlClass CustomImagePlaceHolder, and we have defined that again while registering.
Now to set the value of depndency property, by using our properties as below:
Now this is how it go, we set the value from our code behind or xaml to the source property defined above, and inturn it sets the value of the dependecy property ImageUri, which inturn sets the value in the template binding Source, as we have registered ImageUri as Source, that is presennt generic.xaml.