Export (0) Print
Expand All

DependencyProperty.GetMetadata Method

Retrieves the property metadata value for the dependency property as registered to the specified Type.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

public PropertyMetadata GetMetadata(
	Type forType
)

Parameters

forType
Type: System.Type
The specific type from which to retrieve the dependency property metadata.

Return Value

Type: System.Windows.PropertyMetadata
A property metadata object.

In WPF, specifying either the type or an object reference to obtain a type from is necessary because the metadata can vary from the original registration. (This is because WPF supports AddOwner or OverrideMetadata calls that alter the metadata of the dependency property as it exists on a type.) Silverlight does not support a similar AddOwner or OverrideMetadata technique. However, the Silverlight  implementation of GetMetadata still requires a type to be passed for compatibility reasons. To get a value to use as forType, you can either call typeof() for the known owner type of the dependency property, or use an available type reference you have obtained by some other means.

The most common scenario for getting a PropertyMetadata value is to check the DefaultValue. That is the only public property available on the PropertyMetadata type in Silverlight.

The following example implements a utility method that reports the default value of a given dependency property as it exists in FrameworkElement, based on the default value registered and stored in the metadata:


public static object GetDefaultValueForFrameworkDP(DependencyProperty dpIdentifier)
{
    PropertyMetadata metadataInfo = dpIdentifier.GetMetadata(typeof(FrameworkElement));
    return metadataInfo.DefaultValue;
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2014 Microsoft