DependencyObject class

Expand
This topic has not yet been rated - Rate this topic

DependencyObject class

[This documentation is preliminary and is subject to change.]

Applies to: Metro style apps only

Represents an object that participates in the dependency property system. DependencyObject is the immediate base class of many important UI-related classes, such as UIElement, Geometry, FrameworkTemplate, Style, and ResourceDictionary.

Inheritance

Object
  DependencyObject

Syntax


public class DependencyObject : Object

Attributes

MarshalingBehaviorAttribute(Agile)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)
WebHostHiddenAttribute()

Members

The DependencyObject class has these types of members:

Constructors

The DependencyObject class has these constructors.

ConstructorDescription
DependencyObject Provides base class initialization behavior for DependencyObject derived classes.

 

Methods

The DependencyObject class has these methods. It also inherits methods from the Object class.

MethodDescription
ClearValue Clears the local value of a dependency property.
GetAnimationBaseValue Returns any base value established for a dependency property, which would apply in cases where an animation is not active.
GetValue Returns the current effective value of a dependency property from a DependencyObject.
ReadLocalValue Returns the local value of a dependency property, if a local value is set.
SetValue Sets the local value of a dependency property on a DependencyObject.

 

Properties

The DependencyObject class has these properties.

PropertyAccess typeDescription

Dispatcher

Read-onlyGets the CoreDispatcher that this object is associated with.

 

Remarks

The DependencyObject class enables dependency property system services on its many derived classes. For more info about the dependency property concept, see Dependency properties overview.

The dependency 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 dependency property system is DependencyProperty. DependencyProperty 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.

Here are some notable services and characteristics that DependencyObject provides or supports:

  • 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 property in your DependencyObject class.
  • 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 property in your class.
  • Get and Set utility methods for values of any dependency properties that exist on the DependencyObject.
  • Additional utility for examining metadata or property values.
  • Dispatcher 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. These concepts are explained in more detail in Dependency properties overview. See also Data binding with XAML.

Examples

This 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 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(
          "Bouyancy",
          typeof(Bouyancy),
          typeof(AquariumServices),
          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);
        }
    }


Requirements

Minimum supported client

Windows 8 Release Preview

Minimum supported server

Windows Server 2012

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

DependencyProperty
Dependency properties overview
Custom dependency properties
Custom attached properties
Attached properties overview

 

 

Build date: 5/22/2012

Did you find this helpful?
(1500 characters remaining)
Community Additions ADD
descendants
Older versions of the class hierarchy documentation included both base classes and descendants. This version only shows the base. I really, really miss being able to inspect the children. Among other things, it was really useful for building a mental model of how the class hierarchy works (which we're all doing right now). For example, which UI layout widgets descend from the Panel, as opposed to directly from FrameworkElement? That's useful to know, because Panel provides a lot of core funtionality. The object browser is obviously pulling the same metadata, so the info isn't there either, and class diagrams aren't included in the consumer preview, namespaces tell you nothing about inheritance, so the only way to figure this stuff out is by making guesses and poking around the class library documentation. I'd like those hours of my life back, please....