Could someone please explain why dependency properties are declared as static ?
Because it makes it obvious, that the value of this property cannot be changed after initialization.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With