Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a dependency property? What is its use? [duplicate]

Possiblity:
What is a dependency property?

What is a dependency property? How does it differ from a normal property? What is the purpose of dependency properties? And why it is used, when it is used?

like image 475
Thiru G Avatar asked Mar 22 '11 11:03

Thiru G


3 Answers

Dependency property: A property that is backed by a DependencyProperty.

The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs.

These other inputs might include system properties such as themes and user preference, just-in-time property determination mechanisms such as data binding and animations/storyboards, multiple-use templates such as resources and styles, or values known through parent-child relationships with other elements in the element tree.

It has Following capabilities:

  • The property can be set in a style.

  • The property can be set through data binding.

  • The property can be set with a dynamic resource reference.

  • The property can inherit its value automatically from a parent element in the element tree.

  • The property can be animated.

  • The property can report when the previous value of the property has been changed and the property value can be coerced.

  • The property reports information to WPF, such as whether changing a property value should require the layout system to recompose the visuals for an element.

  • The property receives support in the WPF Designer for Visual Studio. For example, the property can be edited in the Properties window.

(Content taken from MSDN)

like image 197
Shekhar_Pro Avatar answered Sep 17 '22 08:09

Shekhar_Pro


Dependency properties store their values outside the class, so properties can be assigned to an object without having to change the object's class. They also support a situation common in WPF where an object may have very many properties, but only a few have non-default values. Dependency properties can have default values, so this reduces memory usage. There is lots more, read the article: Dependency Properties Overview on MSDN.

like image 31
Douglas Avatar answered Sep 17 '22 08:09

Douglas


I think the MSDN article can give you more information.

From what I read is that a Dependency Property relies on other values.

The purpose of dependency properties is to provide a way to compute the value of a property based on the value of other inputs. These other inputs might include system properties such as themes and user preference, just-in-time property determination mechanisms such as data binding and animations/storyboards, multiple-use templates such as resources and styles, or values known through parent-child relationships with other elements in the element tree. In addition, a dependency property can be implemented to provide self-contained validation, default values, callbacks that monitor changes to other properties, and a system that can coerce property values based on potentially runtime information. Derived classes can also change some specific characteristics of an existing property by overriding dependency property metadata, rather than overriding the actual implementation of existing properties or creating new properties.

like image 20
RvdK Avatar answered Sep 21 '22 08:09

RvdK