PropertyMetadata Constructor (Object, PropertyChangedCallback, CoerceValueCallback)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the PropertyMetadata class with the specified default value and callbacks.

Namespace:   System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

public PropertyMetadata(
	object defaultValue,
	PropertyChangedCallback propertyChangedCallback,
	CoerceValueCallback coerceValueCallback


Type: System.Object

The default value of the dependency property, usually provided as a value of some specific type.

Type: System.Windows.PropertyChangedCallback

Reference to a handler implementation that is to be called by the property system whenever the effective value of the property changes.

Type: System.Windows.CoerceValueCallback

Reference to a handler implementation that is to be called whenever the property system calls CoerceValue against this property.

Exception Condition

defaultValue cannot be set to the value UnsetValue; see Remarks.

If you want to specify a CoerceValueCallback but not a PropertyChangedCallback, you can pass null for the propertyChangedCallback parameter.

The type of the value provided for defaultValue must be match or be related to the type specified in the original registration of the dependency property that this metadata will be applied to. Mismatches between metadata default value type and the type of the dependency property it is being applied to can be difficult to debug, because the mismatch is not detectable during compilation (the mismatch will raise a run-time exception).

Although it is the default per the parameterless constructor, a defaultValue of UnsetValue cannot be specified. Attempting to do so will raise an exception.

static PropertyMetadata pm;
pm = new PropertyMetadata(
    new PropertyChangedCallback(OnCurrentReadingChanged),
    new CoerceValueCallback(CoerceCurrentReading)

.NET Framework
Available since 3.0
Return to top