Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Silverlight 3

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
DependencyObject Class

Represents an object that participates in the Silverlight dependency property system.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
Visual Basic (Declaration)
Public MustInherit Class DependencyObject
Visual Basic (Usage)
Dim instance As DependencyObject
C#
public abstract class DependencyObject

The DependencyObject class enables Silverlight dependency property system services on its many derived classes. For an overview of the dependency property concept, see Dependency Properties Overview.

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.

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.

Although dependency properties can be the target of a data binding, the full support for data binding is not implemented on DependencyObject. To be the target of a data binding, a property must be a dependency property on a FrameworkElement derived classes. For more information, see Data Binding or Dependency Properties Overview.

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.

C#
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);
    }
}

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows..::.AssemblyPart
    System.Windows.Automation.Peers..::.AutomationPeer
    System.Windows.Controls..::.ColumnDefinition
    System.Windows.Controls..::.DataGridColumn
    System.Windows.Controls..::.MultiScaleSubImage
    System.Windows.Controls..::.RowDefinition
    System.Windows.Data..::.CollectionViewSource
    System.Windows..::.Deployment
    System.Windows.Documents..::.Inline
    System.Windows..::.ExternalPart
    System.Windows..::.FrameworkTemplate
    System.Windows..::.Icon
    System.Windows.Ink..::.DrawingAttributes
    System.Windows.Ink..::.Stroke
    System.Windows.Input..::.InputMethod
    System.Windows.Input..::.TouchDevice
    System.Windows.Input..::.TouchPoint
    System.Windows.Media.Animation..::.ColorKeyFrame
    System.Windows.Media.Animation..::.DoubleKeyFrame
    System.Windows.Media.Animation..::.EasingFunctionBase
    System.Windows.Media.Animation..::.KeySpline
    System.Windows.Media.Animation..::.ObjectKeyFrame
    System.Windows.Media.Animation..::.PointKeyFrame
    System.Windows.Media.Animation..::.Timeline
    System.Windows.Media..::.Brush
    System.Windows.Media..::.CacheMode
    System.Windows.Media.Effects..::.Effect
    System.Windows.Media.Effects..::.PixelShader
    System.Windows.Media..::.GeneralTransform
    System.Windows.Media..::.Geometry
    System.Windows.Media..::.GradientStop
    System.Windows.Media..::.ImageSource
    System.Windows.Media..::.MultiScaleTileSource
    System.Windows.Media..::.PathFigure
    System.Windows.Media..::.PathSegment
    System.Windows.Media..::.Projection
    System.Windows.Media..::.TimelineMarker
    System.Windows..::.OutOfBrowserSettings
    System.Windows..::.PresentationFrameworkCollection<(Of <(T>)>)
    System.Windows..::.ResourceDictionary
    System.Windows..::.SetterBase
    System.Windows..::.Style
    System.Windows..::.TriggerAction
    System.Windows..::.TriggerBase
    System.Windows..::.UIElement
    System.Windows..::.VisualState
    System.Windows..::.VisualStateGroup
    System.Windows..::.VisualStateManager
    System.Windows..::.VisualTransition
    System.Windows..::.WindowSettings
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker