DependencyPropertyKey::OverrideMetadata Method (Type^, PropertyMetadata^)
Overrides the metadata of a read-only dependency property that is represented by this dependency property identifier.
Assembly: WindowsBase (in WindowsBase.dll)
Parameters
- forType
-
Type:
System::Type^
The type on which this dependency property exists and metadata should be overridden.
- typeMetadata
-
Type:
System.Windows::PropertyMetadata^
Metadata supplied for this type.
| Exception | Condition |
|---|---|
| InvalidOperationException | Attempted metadata override on a read-write dependency property (cannot be done using this signature). |
| ArgumentException | Metadata was already established for the property as it exists on the provided type. |
Overriding metadata on a read-only dependency property is done for similar reasons as overriding metadata on a read-write dependency property, and is restricted to access at the key level because behaviors specified in the metadata can change the set behavior (the default value, for instance).
As with read-write dependency properties, overriding metadata on a read-only dependency property should only be done prior to that property being placed in use by the property system (this equates to the time that specific instances of objects that register the property are instantiated). 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 equivalent initialization for that class.
This method effectively forwards to the OverrideMetadata method, passing the DependencyPropertyKey instance as the key parameter.
The following example overrides metadata for an existing read-only dependency property that a class inherits. In this case, the scenario goal was to add a coerce value callback that the base property metadata did not have. You could also override metadata for any of the other reasons that overriding metadata is typically appropriate (changing default value, adding FrameworkPropertyMetadataOptions values, etc.)
Available since 3.0