DependencyProperty.GetMetadata 方法

定义

返回与此依赖属性关联的的元数据(只要它对于特定的类型存在)。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.

重载

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.

public:
 System::Windows::PropertyMetadata ^ GetMetadata(Type ^ forType);
public System.Windows.PropertyMetadata GetMetadata (Type forType);
member this.GetMetadata : Type -> System.Windows.PropertyMetadata
Public Function GetMetadata (forType As Type) As PropertyMetadata

参数

forType
Type

要从中检索依赖属性元数据的特定类型。The specific type from which to retrieve the dependency property metadata.

返回

属性元数据对象。A property metadata object.

示例

下面的示例基于依赖项属性的类型获取其元数据。The following example gets metadata for a dependency property based on its type. 该类型是使用 typeof 运算符获取的。The type is obtained by using a typeof operator.

pm = MyStateControl.StateProperty.GetMetadata(typeof(MyStateControl));
pm = MyStateControl.StateProperty.GetMetadata(GetType(MyStateControl))

注解

将类型或对象引用指定为使用类型是必需的,因为元数据与原始注册不同,因为 AddOwnerOverrideMetadata 调用更改了类型上存在的依赖属性的元数据。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.

GetMetadata(DependencyObject)

返回此依赖属性的元数据,因为它存在于指定的对象实例上。Returns the metadata for this dependency property as it exists on the specified object instance.

public:
 System::Windows::PropertyMetadata ^ GetMetadata(System::Windows::DependencyObject ^ dependencyObject);
public System.Windows.PropertyMetadata GetMetadata (System.Windows.DependencyObject dependencyObject);
member this.GetMetadata : System.Windows.DependencyObject -> System.Windows.PropertyMetadata

参数

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.

返回

属性元数据对象。A property metadata object.

示例

下面的示例基于特定的 DependencyObject 实例获取依赖属性的元数据。The following example gets metadata for a dependency property based on a specific DependencyObject instance.

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

注解

指定类型或对象引用是必需的,因为任何给定依赖项属性的元数据都可能与原始注册不同,因为 AddOwnerOverrideMetadata 调用可以优化类型上存在的属性元数据。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.

GetMetadata(DependencyObjectType)

为此依赖属性(当它位于指定的对象实例上时)返回元数据。Returns the metadata for this dependency property as it exists on a specified type.

public:
 System::Windows::PropertyMetadata ^ GetMetadata(System::Windows::DependencyObjectType ^ dependencyObjectType);
public System.Windows.PropertyMetadata GetMetadata (System.Windows.DependencyObjectType dependencyObjectType);
member this.GetMetadata : System.Windows.DependencyObjectType -> System.Windows.PropertyMetadata

参数

dependencyObjectType
DependencyObjectType

一个特定对象,该对象记录需要其中的依赖属性元数据的依赖项对象类型。A specific object that records the dependency object type from which the dependency property metadata is desired.

返回

属性元数据对象。A property metadata object.

示例

下面的示例基于其 DependencyObjectType获取依赖项属性的元数据。The following example gets metadata for a dependency property based on its DependencyObjectType.

DependencyObjectType dt = unrelatedInstance.DependencyObjectType;
pm = UnrelatedStateControl.StateProperty.GetMetadata(dt);
Dim dt As DependencyObjectType = unrelatedInstance.DependencyObjectType
pm = UnrelatedStateControl.StateProperty.GetMetadata(dt)

注解

指定类型或对象引用是必需的,因为任何给定依赖项属性的元数据都可能与原始注册不同,因为 AddOwnerOverrideMetadata 调用可以优化类型上存在的属性元数据。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.

适用于