DependencyProperty.OverrideMetadata DependencyProperty.OverrideMetadata DependencyProperty.OverrideMetadata DependencyProperty.OverrideMetadata Method

定義

提供這個相依性屬性出現在所指定類型的執行個體時所要使用的替代中繼資料,相較於初始相依性屬性註冊中所提供的中繼資料。Supplies alternate metadata for this dependency property when it is present on instances of a specified type, versus the metadata that was provided in the initial dependency property registration.

多載

OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata)

當這個相依性屬性出現在所指定類型的執行個體中時,指定其替代中繼資料,並覆寫從基底類型繼承時存在的相依性屬性中繼資料。Specifies alternate metadata for this dependency property when it is present on instances of a specified type, overriding the metadata that existed for the dependency property as it was inherited from base types.

OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey) OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey) OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey) OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey)

當它出現在所指定類型的執行個體,覆寫在初始相依性屬性登錄中所提供的中繼資料時,提供唯讀相依性屬性的替代中繼資料。Supplies alternate metadata for a read-only dependency property when it is present on instances of a specified type, overriding the metadata that was provided in the initial dependency property registration. 您必須傳遞唯讀相依性屬性的 DependencyPropertyKey,以避免引發例外狀況。You must pass the DependencyPropertyKey for the read-only dependency property to avoid raising an exception.

OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata) OverrideMetadata(Type, PropertyMetadata)

當這個相依性屬性出現在所指定類型的執行個體中時,指定其替代中繼資料,並覆寫從基底類型繼承時存在的相依性屬性中繼資料。Specifies alternate metadata for this dependency property when it is present on instances of a specified type, overriding the metadata that existed for the dependency property as it was inherited from base types.

public:
 void OverrideMetadata(Type ^ forType, System::Windows::PropertyMetadata ^ typeMetadata);
public void OverrideMetadata (Type forType, System.Windows.PropertyMetadata typeMetadata);
member this.OverrideMetadata : Type * System.Windows.PropertyMetadata -> unit
Public Sub OverrideMetadata (forType As Type, typeMetadata As PropertyMetadata)

參數

forType
Type Type Type Type

繼承這個相依性屬性,且將套用所提供替代中繼資料的類型。The type where this dependency property is inherited and where the provided alternate metadata will be applied.

typeMetadata
PropertyMetadata PropertyMetadata PropertyMetadata PropertyMetadata

要套用至覆寫類型上相依性屬性的中繼資料。The metadata to apply to the dependency property on the overriding type.

例外狀況

嘗試覆寫唯讀相依性屬性的中繼資料 (無法使用此簽章完成作業)。An attempt was made to override metadata on a read-only dependency property (that operation cannot be done using this signature).

已經建立相依性屬性的中繼資料,因為它存在於所提供的類型。Metadata was already established for the dependency property as it exists on the provided type.

備註

在屬性系統使用相依性屬性之前, 應該覆寫相依性屬性中繼資料。Dependency property metadata should be overridden before the property system uses the dependency property. 這相當於使用註冊相依性屬性的類別來建立特定實例的時間。This equates to the time that specific instances are created using the class that registers the dependency property. OverrideMetadata的呼叫只能在型別的靜態處理常式中執行, 其本身會提供forType給這個方法的參數, 或是透過類似的具現化。Calls to OverrideMetadata should only be performed within the static constructors of the type that provides itself as the forType parameter of this method, or through similar instantiation. 當擁有者類型的實例存在之後, 嘗試變更中繼資料不會引發例外狀況, 但會導致在屬性系統中出現不一致的行為。Attempting to change metadata after instances of the owner type exist will not raise exceptions, but will result in inconsistent behaviors in the property system.

使用這個方法建立特定衍生類別覆寫的中繼資料之後, 後續嘗試覆寫這個相同衍生類別上的中繼資料將會引發例外狀況。After metadata for a particular derived class override is established with this method, subsequent attempts to override metadata on this same derived class will raise an exception.

提供的中繼資料會與相依性屬性的屬性中繼資料合併, 因為它存在於基底擁有者上。The supplied metadata is merged with the property metadata for the dependency property as it exists on the base owner. 原始基底中繼資料中指定的任何特性都會保存下來;只有在新的中繼資料中特別變更的特性, 才會覆寫基底中繼資料的特性。Any characteristics that were specified in the original base metadata will persist; only those characteristics that were specifically changed in the new metadata will override the characteristics of the base metadata. 如果在新的DefaultValue中繼資料中指定, 則會取代某些特性 (例如)。Some characteristics such as DefaultValue are replaced if specified in the new metadata. 其他專案 (例如PropertyChangedCallback) 則結合在一起。Others, such as PropertyChangedCallback, are combined. 最後, 合併行為取決於用於覆寫的屬性元資料類型, 因此這裡所述的行為適用于相依性屬性所使用WPFWPF的現有屬性中繼資料類別。Ultimately, the merge behavior depends on the property metadata type being used for the override, so the behavior described here is for the existing property metadata classes used by WPFWPF dependency properties. 如需詳細資訊, 請參閱相依性屬性中繼資料架構屬性中繼資料For details, see Dependency Property Metadata and Framework Property Metadata.

OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey) OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey) OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey) OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey)

當它出現在所指定類型的執行個體,覆寫在初始相依性屬性登錄中所提供的中繼資料時,提供唯讀相依性屬性的替代中繼資料。Supplies alternate metadata for a read-only dependency property when it is present on instances of a specified type, overriding the metadata that was provided in the initial dependency property registration. 您必須傳遞唯讀相依性屬性的 DependencyPropertyKey,以避免引發例外狀況。You must pass the DependencyPropertyKey for the read-only dependency property to avoid raising an exception.

public:
 void OverrideMetadata(Type ^ forType, System::Windows::PropertyMetadata ^ typeMetadata, System::Windows::DependencyPropertyKey ^ key);
public void OverrideMetadata (Type forType, System.Windows.PropertyMetadata typeMetadata, System.Windows.DependencyPropertyKey key);
member this.OverrideMetadata : Type * System.Windows.PropertyMetadata * System.Windows.DependencyPropertyKey -> unit
Public Sub OverrideMetadata (forType As Type, typeMetadata As PropertyMetadata, key As DependencyPropertyKey)

參數

forType
Type Type Type Type

繼承這個相依性屬性,且將套用所提供替代中繼資料的類型。The type where this dependency property is inherited and where the provided alternate metadata will be applied.

typeMetadata
PropertyMetadata PropertyMetadata PropertyMetadata PropertyMetadata

要套用至覆寫類型上相依性屬性的中繼資料。The metadata to apply to the dependency property on the overriding type.

key
DependencyPropertyKey DependencyPropertyKey DependencyPropertyKey DependencyPropertyKey

唯讀相依性屬性的存取索引鍵。The access key for a read-only dependency property.

備註

此簽章提供唯讀相依性屬性 identifier (DependencyPropertyKey) 方法的基礎執行。This signature provides underlying implementation for a read-only dependency property identifier (DependencyPropertyKey) method. 如果覆寫讀寫相依性屬性的中繼資料, OverrideMetadata(Type, PropertyMetadata)請使用。If overriding metadata for a read-write dependency property, use OverrideMetadata(Type, PropertyMetadata).

在屬性系統使用相依性屬性之前, 應該覆寫相依性屬性中繼資料。Dependency property metadata should be overridden before the property system uses the dependency property. 這相當於為註冊相依性屬性的類別建立特定物件的時間。This equates to the time that specific objects are created for the class that registers the dependency property. OverrideMetadata的呼叫只能在型別的靜態處理常式中執行, 其本身會提供forType給這個方法的參數, 或是透過類似的具現化。Calls to OverrideMetadata should only be performed within the static constructors of the type that provides itself as the forType parameter of this method, or through similar instantiation. 當擁有者類型的實例存在之後, 嘗試變更中繼資料不會引發例外狀況, 但會導致在屬性系統中出現不一致的行為。Attempting to change metadata after instances of the owner type exist will not raise exceptions, but will result in inconsistent behaviors in the property system.

使用這個方法建立特定衍生類別覆寫的中繼資料之後, 後續嘗試覆寫這個相同衍生類別上的中繼資料將會引發例外狀況。After metadata for a particular derived class override is established with this method, subsequent attempts to override metadata on this same derived class will raise an exception.

提供的中繼資料會與相依性屬性的屬性中繼資料合併, 因為它存在於基底擁有者上。The supplied metadata is merged with the property metadata for the dependency property as it exists on the base owner. 原始基底中繼資料中指定的任何特性都會保存下來;只有在新的中繼資料中特別變更的特性, 才會覆寫基底中繼資料的特性。Any characteristics that were specified in the original base metadata will persist; only those characteristics that were specifically changed in the new metadata will override the characteristics of the base metadata. 如果在新的DefaultValue中繼資料中指定, 則會取代某些特性 (例如)。Some characteristics such as DefaultValue are replaced if specified in the new metadata. 其他專案 (例如PropertyChangedCallback) 則結合在一起。Others, such as PropertyChangedCallback, are combined. 合併行為取決於用於覆寫的屬性元資料類型。The merge behavior depends on the property metadata type being used for the override. 如需詳細資訊, 請參閱相依性屬性中繼資料架構屬性中繼資料For details, see Dependency Property Metadata and Framework Property Metadata.

適用於