DependencyObject Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Represents an object that participates in the Windows Phone dependency property system. DependencyObject is the immediate base class of several other important Windows Phone classes, such as UIElement, Geometry, FrameworkTemplate, Style, and ResourceDictionary.


Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public abstract class DependencyObject

The DependencyObject type exposes the following members.

Protected methodDependencyObjectInitializes a new instance of the DependencyObject class.

Public propertyDispatcherGets the Dispatcher this object is associated with.

Public methodCheckAccessDetermines whether the calling thread has access to this object.
Public methodClearValueClears the local value of a dependency property.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetAnimationBaseValueReturns any base value established for a Windows Phone dependency property, which would apply in cases where an animation is not active.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValueReturns the current effective value of a dependency property from a DependencyObject.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodReadLocalValueReturns the local value of a dependency property, if a local value is set.
Public methodSetValueSets the local value of a dependency property on a DependencyObject.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

The DependencyObject class enables Windows Phone dependency property system services on its many derived classes. For an overview of the dependency property concept, see Dependency properties for Windows Phone 8.

The property system's primary function is to compute the values of properties, and to provide system notification about values that have changed. Another key class that participates in the property system is DependencyPropertyDependencyProperty enables the registration of dependency properties into the property system, whereas DependencyObject as a base class enables objects to use and set the dependency properties.

DependencyObject services and characteristics include the following:

  • Dependency property hosting support.

  • Custom dependency property hosting support. You register a dependency property by calling the Register method, and storing the method's return value as a public static field in your DependencyObject class. Also, the ownerType parameter of Register must be the type of your DependencyObject.

  • Attached property hosting support.

  • Custom attached property hosting support. You register a dependency property for the attached property usage by calling the RegisterAttached method, and storing the method's return value as a public static field in your class.

  • Get and set utility methods for values of any dependency properties that exist on the DependencyObject.

  • Dispatcher APIs for advanced threading scenarios.

  • Basic data binding and styling support, by enabling properties to be set as expressions to be evaluated at some later point in an object's lifetime..

It is not typical to derive directly from DependencyObject for most application scenarios. Instead you might derive from a specific control, from one of the control base classes (ContentControl; Control; ItemsControl), from FrameworkElement, or from non-control classes that still participate in UI such as Panel or Grid. Deriving from DependencyObject might be appropriate if you are defining a business or data storage object where you want dependency properties to be active, or if you are creating a service support class that will own attached properties. However, for basic data objects, you might instead implement the interface INotifyPropertyChanged, because by implementing the interface you could base your data on any object. For more information, see Data binding for Windows Phone 8.

DependencyObject dependency properties can be the target of a data binding. In XAML, you can specify a Binding attribute value for such properties, just like any other case where data binding a property is supported on FrameworkElement. However, DependencyObject does not implement DataContext or SetBinding. Thus, in order to inherit a data context, there must be a containing FrameworkElement that defines that data context. For more information, see Data binding for Windows Phone 8 or Dependency properties for Windows Phone 8.

The following example defines a class that derives from DependencyObject, and defines an attached property along with the identifier field. The scenario for this class is that it is a service class that declares an attached property that other UI elements can set in XAML, and the service potentially acts on the attached property values on those UI elements at run time.

public abstract class AquariumServices : DependencyObject
    public enum Bouyancy {Floats,Sinks,Drifts}

    public static readonly DependencyProperty BouyancyProperty = DependencyProperty.RegisterAttached(
      new PropertyMetadata(Bouyancy.Floats)
    public static void SetBouyancy(DependencyObject element, Bouyancy value)
        element.SetValue(BouyancyProperty, value);
    public static Bouyancy GetBouyancy(DependencyObject element)
        return (Bouyancy)element.GetValue(BouyancyProperty);

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


© 2015 Microsoft