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.
Assembly: System.Windows (in System.Windows.dll)
The DependencyObject type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | CheckAccess | Determines whether the calling thread has access to this object. |
![]() | ClearValue | Clears the local value of a dependency property. |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetAnimationBaseValue | Returns any base value established for a Windows Phone dependency property, which would apply in cases where an animation is not active. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | GetValue | Returns the current effective value of a dependency property from a DependencyObject. |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | 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. |
![]() | ToString | Returns 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 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.
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( "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.Windows::DependencyObject
Microsoft.Phone.Maps.Controls::MapElement
Microsoft.Phone.Maps.Controls::MapOverlay
Microsoft.Phone.Shell::ProgressIndicator
Microsoft.Phone.Shell::SystemTray
System.Windows::AssemblyPart
System.Windows.Automation.Peers::AutomationPeer
System.Windows.Controls::ColumnDefinition
System.Windows.Controls::MultiScaleSubImage
System.Windows.Controls::RowDefinition
System.Windows.Data::CollectionViewSource
System.Windows::DependencyObjectCollection<T>
System.Windows::Deployment
System.Windows.Documents::TextElement
System.Windows::ExternalPart
System.Windows::FrameworkTemplate
System.Windows::Icon
System.Windows.Ink::DrawingAttributes
System.Windows.Ink::Stroke
System.Windows.Input::InputMethod
System.Windows.Input::InputScope
System.Windows.Input::InputScopeName
System.Windows.Input::ManipulationDelta
System.Windows.Input::ManipulationVelocities
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::CaptureDevice
System.Windows.Media::CaptureSource
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.Navigation::JournalEntry
System.Windows::PresentationFrameworkCollection<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


