Compartir a través de


DependencyProperty.GetMetadata Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Function GetMetadata ( _
    forType As Type _
) As PropertyMetadata
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.

Remarks

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.

Examples

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;
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

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

Platforms

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