DependencyProperty.GetMetadata 方法

定義

傳回與特定類型的此相依性屬性相關聯的中繼資料。 這可以是第一次註冊相依性屬性的類型 (之後會加一),或透過繼承取得相依性屬性但特別覆寫中繼資料的類型。

多載

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

要從中擷取相依性屬性中繼資料的特定類型。

傳回

PropertyMetadata

屬性中繼資料物件。

範例

下列範例會根據其類型取得相依性屬性的中繼資料。 類型是使用 typeof 運算子取得。

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

備註

需要指定型別或物件參考做為類型,因為中繼資料可能會因 AddOwnerOverrideMetadata 呼叫改變相依性屬性的中繼資料而有所不同,因為它存在於類型上。

適用於

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

檢查了相依性物件的類型,以判斷中繼資料應該來自於相依性屬性的哪一個特定類型版本。

傳回

PropertyMetadata

屬性中繼資料物件。

範例

下列範例會根據特定 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

記錄需要相依性屬性中繼資料之相依性物件類型的特定物件。

傳回

PropertyMetadata

屬性中繼資料物件。

範例

下列範例會根據其 DependencyObjectType 取得相依性屬性的中繼資料。

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

備註

需要指定型別或物件參考,因為任何給定相依性屬性的中繼資料可能會因 原始註冊 AddOwner 而有所不同,或 OverrideMetadata 呼叫可精簡屬性中繼資料,因為該屬性中繼資料存在於類型上。

適用於