#116 – Dependency Property Values Are Stored in the DependencyObject

Standard CLR property values are stored in the instance of the object where the property is defined.  Even if you never change a property from its default value, it still takes up memory in the object.

Values of dependency properties are stored only if a dependency property has been set to a non-default value.  For properties that you haven’t set, the default value for the property is returned whenever a client reads the property.

Values for dependency properties that have been set are stored in an array in the object that inherits from DependencyObject and owns the property.  This array, as well as the GetValue and SetValue methods for reading/writing properties, is part of the implementation of DependencyObject that a derived class inherits. The internal array contains effective values for each dependency property whose value has been set.

Advertisements

#29 – Dependency Properties

DependencyObject is the base class for classes that support dependency properties.

A dependency property in WPF is similar to a standard CLR property, but more powerful.  Dependency properties:

  • Obtain their values from one of a number of different sources
  • Support inheritance of property values
  • Support notification, when a property value changes

If a class derives from DependencyObject, that class can then register its own dependency properties and call methods to get/set the values of its dependency properties.