Class DependencyObject
Represents an object that can store attached properties, and whose registered properties (see RegisterReferenceAttribute) participate in the value-precedence system used by styles, visual states, and animations.
public abstract class DependencyObject : BindableObject, INotifyPropertyChanging, IBindingTarget, INotifyPropertyChanged
- Inheritance
-
DependencyObject
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
DependencyObject()
Initializes a new instance of the DependencyObject class, binding it to the Current registry for its lifetime.
protected DependencyObject()
Properties
PropertyRegistry
Gets the PropertyRegistry this instance resolves its properties through, captured when it was constructed.
public PropertyRegistry PropertyRegistry { get; }
Property Value
Remarks
Captured once rather than read per access so the object keeps using one registry even if a different one later becomes Current - an object whose property references came from two registries would have its value-precedence bookkeeping split between them. Use For(object) to reach this from code holding an arbitrary target.
Methods
GetPropertyStore()
Gets the IPropertyStore registered for this instance's runtime type, resolving and registering it on first use.
public IPropertyStore GetPropertyStore()
Returns
- IPropertyStore
The property store for GetType().
SetProperty<T>(ref T, T, string?)
Sets a property's backing field and raises PropertyChanged when the value changes. An assignment of the value the property already holds still counts as a local value, so a style applied later doesn't replace it.
protected bool SetProperty<T>(ref T field, T newValue, string? propertyName = null)
Parameters
fieldTThe property's backing field.
newValueTThe value to assign.
propertyNamestringThe property's name; filled in by the compiler.
Returns
Type Parameters
TThe property's type.
Remarks
Without this, new Button { HorizontalAlignment = HorizontalAlignment.Stretch } would change nothing
(Stretch is the default), wouldn't be recorded, and the theme's style
would override it once the button joins a canvas.