Returns the current effective value of a dependency property on this instance of a DependencyObject.
Assembly: WindowsBase (in WindowsBase.dll)
The specified dp or its value was invalid, or the specified dp does not exist.
The effective value is the value of the property that is returned by the property system to any caller that is requesting the value. The effective value is the result of the property system having evaluated all the possible inputs that participate in the property system value precedence. This includes coercion and animation. For more information, see Dependency Property Value Precedence.
This method will never return UnsetValue. The UnsetValue is a sentinel value for the property system that is used in various capacities internally and occasionally also exposed through coercion callbacks.
If you are not sure what the property's type should be, you can query the identifier of the requested dependency property to determine whether there is a more specific PropertyType that the return value can be converted to.
This example shows how to back a common language runtime (CLR) property with a DependencyProperty field, thus defining a dependency property. When you define your own properties and want them to support many aspects of Windows Presentation Foundation (WPF) functionality, including styles, data binding, inheritance, animation, and default values, you should implement them as a dependency property.
The following example first registers a dependency property by calling the Register method. The name of the identifier field that you use to store the name and characteristics of the dependency property must be the Name you chose for the dependency property as part of the Register call, appended by the literal string Property. For instance, if you register a dependency property with a Name of Location, then the identifier field that you define for the dependency property must be named LocationProperty.
In this example, the name of the dependency property and its CLR accessor is State; the identifier field is StateProperty; the type of the property is Boolean; and the type that registers the dependency property is MyStateControl.
If you fail to follow this naming pattern, designers might not report your property correctly, and certain aspects of property system style application might not behave as expected.
You can also specify default metadata for a dependency property. This example registers the default value of the State dependency property to be false.
Public Class MyStateControl Inherits ButtonBase Public Sub New() MyBase.New() End Sub Public Property State() As Boolean Get Return CType(Me.GetValue(StateProperty), Boolean) End Get Set(ByVal value As Boolean) Me.SetValue(StateProperty, value) End Set End Property Public Shared ReadOnly StateProperty As DependencyProperty = DependencyProperty.Register("State", GetType(Boolean), GetType(MyStateControl),New PropertyMetadata(False)) End Class
For more information about how and why to implement a dependency property, as opposed to just backing a CLR property with a private field, see Dependency Properties Overview.
|How to: Register an Attached Property||This example shows how to register an attached property and provide public accessors so that you can use the property in both Extensible Application Markup Language (XAML) and code. Attached properties are a syntax concept defined by Extensible Application Markup Language (XAML). Most attached properties for WPF types are also implemented as dependency properties. You can use dependency properties on any DependencyObject types.|
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.