Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are dependency properties "static"?

Could someone please explain why dependency properties are declared as static ?

like image 916
Kishore Kumar Avatar asked Jun 07 '10 12:06

Kishore Kumar


People also ask

Why is dependency property static readonly?

Because it makes it obvious, that the value of this property cannot be changed after initialization.

What are dependency properties?

A dependency property can reference a value through data binding. Data binding works through a specific markup extension syntax in XAML, or the Binding object in code. With data binding, determination of the final property value is deferred until run time, at which time the value is obtained from a data source.

What is the biggest feature of dependency property?

Arguably the biggest feature of a dependency property is its built-in ability to provide change notification. The motivation for adding such intelligence to properties is to enable rich functionality directly from declarative markup.

What is the difference between property and dependency property?

A dependency property provides functionality that extends the functionality of a property as opposed to a property that is backed by a field. Often, each such functionality represents or supports a specific feature of the overall WPF set of features.


2 Answers

When you declare a DependencyProperty, you are declaring the definition of that property, rather than the storage space for the property's value (as would be the case with the regular property declaration). There is only one definition of the property for the whole class - as opposed to one definition per instance of the class - and so it is static.

like image 96
Dan Puzey Avatar answered Oct 05 '22 23:10

Dan Puzey


The field you declare as static is only the identifier of a dependency property, not the value of the property. It is shared across all instances of the class, and is used to get/set the value of the property for each instance.

like image 43
Thomas Levesque Avatar answered Oct 06 '22 00:10

Thomas Levesque