DependencyProperty.GetMetadata 方法

定義

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

多載

GetMetadata(Type)

傳回這個相依性屬性的中繼資料,因為這個屬性位於指定的現有類型。

GetMetadata(DependencyObject)

傳回這個相依性屬性的中繼資料,因為這個屬性位於指定的物件執行個體。

GetMetadata(DependencyObjectType)

傳回存在於所指定類型之這個相依性屬性的中繼資料。

GetMetadata(Type)

傳回這個相依性屬性的中繼資料,因為這個屬性位於指定的現有類型。

C#
public System.Windows.PropertyMetadata GetMetadata (Type forType);

參數

forType
Type

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

傳回

PropertyMetadata

屬性中繼資料物件。

範例

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

C#
pm = MyStateControl.StateProperty.GetMetadata(typeof(MyStateControl));

備註

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

適用於

.NET Framework 4.8 和其他版本
產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

GetMetadata(DependencyObject)

傳回這個相依性屬性的中繼資料,因為這個屬性位於指定的物件執行個體。

C#
public System.Windows.PropertyMetadata GetMetadata (System.Windows.DependencyObject dependencyObject);

參數

dependencyObject
DependencyObject

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

傳回

PropertyMetadata

屬性中繼資料物件。

範例

下列範例會根據特定 DependencyObject 實例取得相依性屬性的中繼資料。

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

備註

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

當您根據實例要求屬性中繼資料時,實際上只是傳遞 實例,以便內部評估其類型。 相依性屬性中繼資料不會因每個實例而有所不同;任何指定的型別屬性組合一律一致。

適用於

.NET Framework 4.8 和其他版本
產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

GetMetadata(DependencyObjectType)

傳回存在於所指定類型之這個相依性屬性的中繼資料。

C#
public System.Windows.PropertyMetadata GetMetadata (System.Windows.DependencyObjectType dependencyObjectType);

參數

dependencyObjectType
DependencyObjectType

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

傳回

PropertyMetadata

屬性中繼資料物件。

範例

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

C#
DependencyObjectType dt = unrelatedInstance.DependencyObjectType;
pm = UnrelatedStateControl.StateProperty.GetMetadata(dt);

備註

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

適用於

.NET Framework 4.8 和其他版本
產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7