DependencyProperty.GetMetadata 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回与此依赖属性关联的元数据,因为它存在特定类型。 这可以是首次注册依赖属性的类型、随后向其添加的依赖项属性的类型,也可以是通过继承获取依赖属性的类型,但元数据是专门重写的。
重载
| 名称 | 说明 |
|---|---|
| GetMetadata(Type) |
返回此依赖属性的元数据,因为它存在于指定的现有类型上。 |
| GetMetadata(DependencyObject) |
返回此依赖属性的元数据,因为它存在于指定的对象实例上。 |
| GetMetadata(DependencyObjectType) |
返回此依赖属性的元数据,因为它存在于指定类型上。 |
GetMetadata(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
要从中检索依赖属性元数据的特定类型。
返回
属性元数据对象。
示例
以下示例根据其类型获取依赖属性的元数据。 该类型是使用 typeof 运算符获取的。
pm = MyStateControl.StateProperty.GetMetadata(typeof(MyStateControl));
pm = MyStateControl.StateProperty.GetMetadata(GetType(MyStateControl))
注解
指定类型或对象引用以用作类型是必要的,因为元数据可能因更改类型上存在的依赖属性的元数据或AddOwner调用而因原始注册OverrideMetadata而异。
适用于
GetMetadata(DependencyObject)
返回此依赖属性的元数据,因为它存在于指定的对象实例上。
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
Public Function GetMetadata (dependencyObject As DependencyObject) As PropertyMetadata
参数
- dependencyObject
- DependencyObject
检查类型的依赖项对象,以确定元数据应来自哪个类型特定的依赖属性版本。
返回
属性元数据对象。
示例
以下示例基于特定 DependencyObject 实例获取依赖属性的元数据。
pm = MyAdvancedStateControl.StateProperty.GetMetadata(advancedInstance);
pm = MyAdvancedStateControl.StateProperty.GetMetadata(advancedInstance)
注解
指定类型或对象引用是必需的,因为任何给定依赖属性的元数据可能因原始注册 AddOwner 而异,或者 OverrideMetadata 调用这些元数据可以优化类型上存在的属性元数据。
基于实例请求属性元数据时,实际上只需传递实例,以便可以在内部评估其类型。 依赖属性元数据不会因实例而异;对于任何给定的类型属性组合,它始终一致。
适用于
GetMetadata(DependencyObjectType)
返回此依赖属性的元数据,因为它存在于指定类型上。
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
Public Function GetMetadata (dependencyObjectType As DependencyObjectType) As PropertyMetadata
参数
- dependencyObjectType
- DependencyObjectType
一个特定对象,用于记录需要依赖属性元数据的依赖对象类型。
返回
属性元数据对象。
示例
以下示例基于依赖项 DependencyObjectType属性获取依赖项属性的元数据。
DependencyObjectType dt = unrelatedInstance.DependencyObjectType;
pm = UnrelatedStateControl.StateProperty.GetMetadata(dt);
Dim dt As DependencyObjectType = unrelatedInstance.DependencyObjectType
pm = UnrelatedStateControl.StateProperty.GetMetadata(dt)
注解
指定类型或对象引用是必需的,因为任何给定依赖属性的元数据可能因原始注册 AddOwner 而异,或者 OverrideMetadata 调用这些元数据可以优化类型上存在的属性元数据。