Editar

Compartilhar via


DependencyProperty.OverrideMetadata Method

Definition

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.

Overloads

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)

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. You must pass the DependencyPropertyKey for the read-only dependency property to avoid raising an exception.

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)

Parameters

forType
Type

The type where this dependency property is inherited and where the provided alternate metadata will be applied.

typeMetadata
PropertyMetadata

The metadata to apply to the dependency property on the overriding type.

Exceptions

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.

Remarks

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. 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. Some characteristics such as DefaultValue are replaced if specified in the new metadata. Others, such as PropertyChangedCallback, are combined. 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 WPF dependency properties. For details, see Dependency Property Metadata and Framework Property Metadata.

Applies to

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. 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)

Parameters

forType
Type

The type where this dependency property is inherited and where the provided alternate metadata will be applied.

typeMetadata
PropertyMetadata

The metadata to apply to the dependency property on the overriding type.

key
DependencyPropertyKey

The access key for a read-only dependency property.

Remarks

This signature provides underlying implementation for a read-only dependency property identifier (DependencyPropertyKey) method. 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. 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. Some characteristics such as DefaultValue are replaced if specified in the new metadata. 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.

Applies to