DependencyProperty.GetMetadata Method

Definition

Returns the metadata associated with this dependency property as it exists for a particular type. This can be the type where the dependency property was first registered, one to which it was added subsequently, or a type where the dependency property was obtained through inheritance but the metadata was specifically overridden.

Overloads

GetMetadata(Type)

Returns the metadata for this dependency property as it exists on a specified existing type.

GetMetadata(DependencyObject)

Returns the metadata for this dependency property as it exists on the specified object instance.

GetMetadata(DependencyObjectType)

Returns the metadata for this dependency property as it exists on a specified type.

GetMetadata(Type)

Returns the metadata for this dependency property as it exists on a specified existing type.

C#
public System.Windows.PropertyMetadata GetMetadata(Type forType);

Parameters

forType
Type

The specific type from which to retrieve the dependency property metadata.

Returns

A property metadata object.

Examples

The following example gets metadata for a dependency property based on its type. The type is obtained by using a typeof operator.

C#
pm = MyStateControl.StateProperty.GetMetadata(typeof(MyStateControl));

Remarks

Specifying either the type or an object reference to use as type is necessary because the metadata can vary from the original registration due either to AddOwner or OverrideMetadata calls that alter the metadata of the dependency property as it exists on a type.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

GetMetadata(DependencyObject)

Returns the metadata for this dependency property as it exists on the specified object instance.

C#
public System.Windows.PropertyMetadata GetMetadata(System.Windows.DependencyObject dependencyObject);

Parameters

dependencyObject
DependencyObject

A dependency object that is checked for type, to determine which type-specific version of the dependency property the metadata should come from.

Returns

A property metadata object.

Examples

The following example gets metadata for a dependency property based on a specific DependencyObject instance.

C#
pm = MyAdvancedStateControl.StateProperty.GetMetadata(advancedInstance);

Remarks

Specifying either the type or an object reference is necessary because the metadata of any given dependency property can vary from the original registration due either to AddOwner or OverrideMetadata calls that can refine the property metadata as it exists on a type.

When you request property metadata based on an instance, you are really just passing the instance so that its type can be evaluated internally. Dependency property metadata does not vary per instance; it is always consistent for any given type-property combination.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

GetMetadata(DependencyObjectType)

Returns the metadata for this dependency property as it exists on a specified type.

C#
public System.Windows.PropertyMetadata GetMetadata(System.Windows.DependencyObjectType dependencyObjectType);

Parameters

dependencyObjectType
DependencyObjectType

A specific object that records the dependency object type from which the dependency property metadata is desired.

Returns

A property metadata object.

Examples

The following example gets metadata for a dependency property based on its DependencyObjectType.

C#
DependencyObjectType dt = unrelatedInstance.DependencyObjectType;
pm = UnrelatedStateControl.StateProperty.GetMetadata(dt);

Remarks

Specifying either the type or an object reference is necessary because the metadata of any given dependency property can vary from the original registration due either to AddOwner or OverrideMetadata calls that can refine the property metadata as it exists on a type.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9