Class DependencyObject
DependencyObject is an object that participates in the property dependency system
public class DependencyObject : DispatcherObject, IBaseObject, IDisposableObject, IDisposable
- Inheritance
-
DependencyObject
- Implements
- Derived
- Extension Methods
Remarks
DependencyObject encompasses all property engine services. It's primary function is providing facilities to compute a property's value based on other properties.
The Property Engine introduces a new type of property: attached properties. Attached properties are identified via DependencyProperty and are read and written using GetValue and SetValue.
Attached properties may be set and queried on any DependencyObject-derived type.
Expression is used to define relationships between properties. SetValue is used to apply the Expression to the property on the instance.
DependencyObject services include the following:
- Dependency-based property value evaluation through Expressions
- Property invalidation dependent traversal through Expressions
- Attached property support
- Invalidation notification services
Constructors
- DependencyObject()
Default DependencyObject constructor
Properties
- DependencyObjectType
Returns the DType that represents the CLR type of this instance
- IsSealed
Indicates whether or not this object is in a Read-Only state; when in a Read-Only state, SetValue is not permitted, though the effective value for a property may change.
Methods
- ClearValue(DependencyProperty)
Clears the local value of a property
- ClearValue(DependencyPropertyKey)
Clears the local value of a property
- CoerceValue(DependencyProperty)
Coerce a property value
- Equals(object)
We override Equals() to seal it to prevent custom Equals() implementations.
There are only two scenarios where overriding Equals makes sense:
1. You are a value type (passed by copy). 2. You are an immutable reference type (e.g., System.String).
Otherwise you are going to cause problems with keyed and some types of sorted datastructures because your values can mutate to be equals or not equals while they reside in the store (bad news for System.Collections(.Generic)).
Furthermore, defining equality for two DOs is a very slippery slope. Are two brushes "equal" if they both paint red? What if one is only red this frame because it is animated? What if one is databound? What if one is frozen? ...and so on.
Since a DO can never be immutable (attached properties, etc.) it makes sense to disallow overriding of Equals.
- GetHashCode()
CS0659: Required when overriding Equals(). Overriding GetHashCode() is a bad idea for similar reasons.
- GetLocalValueEnumerator()
Create a local value enumerator for this instance
- GetValue(DependencyProperty)
Retrieve the value of a property
- InvalidateProperty(DependencyProperty)
Invalidates a property
- OnPropertyChanged(DependencyPropertyChangedEventArgs)
Notification that a specified property has been changed
- ReadLocalValue(DependencyProperty)
Retrieve the local value of a property (if set)
- SetCurrentValue(DependencyProperty, object)
Sets the value of a property without changing its value source.
- SetValue(DependencyProperty, object)
Sets the local value of a property
- SetValue(DependencyPropertyKey, object)
Sets the local value of a property
- ShouldSerializeProperty(DependencyProperty)
Override this method to control whether a DependencyProperty should be serialized. The base implementation returns true if the property is set (locally) on this object.