Dependency Property (DP)
Dependency Property is a property that automatically notify the interested parties each time their Values are changed. Dependency Property is designed to support – DataBinding, Animations, default values, Property Validation, Property metadata.
Most of the Properties in framework are implemented as Dependency Property, thus allowing us to bind or use them in animations.
HOW TO REGSTER DP ?
here I am sharing my study along with this.
public static readonly DependencyProperty SizeProperty =
“SIZE”, ———-> Name of DP
typeof(double), ———-> Return Type here it is Double
typeof(MyControl), ——-> Type of class for which you register DP
new PropertyChangedCallback(onSizeChanged) ) );
SO WHAT ARE THESE THINGS ? IT SEEMS DIFFERENT TO NORMAL PROPERTY ?
Lets see –
- DP must be Static and ReadOnly and return type must be DependencyProperty.
- Then, comes registration part – This is done using Register Method of DependencyProperty class.
- The first parameter here is – Name of DependencyProperty ( The name should be same as DP name but, without “Property” word.
- Second parameter is – Return type of the property ( here it is double )
- Third paramter is – Type of class for which you register the DP.
- Last Parameter is – Default value and callback method to be called once the property value changes.
For more details – Dependency Property