What is Dependency Property ?


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 =
DepenedncyProperty.Register (
“SIZE”,                   ———-> Name of DP
typeof(double),   ———-> Return Type here it is Double
typeof(MyControl), ——-> Type of class for which you register DP
new PropertMetaData(
0,
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

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s