PropertyMetadata.Create(CreateDefaultValueCallback) method

Applies to Windows and Windows Phone

Creates a PropertyMetadata value, specifying a callback that establishes a default value for a dependency property.


public static PropertyMetadata Create(
  CreateDefaultValueCallback createDefaultValueCallback



Type: CreateDefaultValueCallback

A reference to the callback method that provides a default property value.

Return value

Type: PropertyMetadata

The newly created dependency property metadata.


Use a CreateDefaultValueCallback instead of a fixed constant default value in any case where the default value of a dependency property might be thread-bound. The CreateDefaultValueCallback becomes a factory for default values whenever there is a need to get default values of properties on threads other than the main UI thread.

In order to establish a CreateDefaultValueCallback pattern for a dependency property, use one of the static Create methods instead of using the PropertyMetadata constructor when you define the metadata for the property. That metadata is submitted to the Register call. For more info, see Custom dependency properties. As with a property-changed callback, the CreateDefaultValueCallback method should be a static method of the type that registers the dependency property. The method does not have to be public.


This example shows pseudocode for using CreateDefaultValueCallback in a custom dependency property scenario. Specifically, this creates PropertyMetadata to be used in a DependencyProperty.Register call (not shown).

PropertyMetadata metadata = PropertyMetadata.Create(
    new CreateDefaultValueCallback(() =>
        return new CustomClass() //a DependencyObject
            CustomProperty1 = "default", //DependencyProperty of type String 
            CustomProperty2 = -1; //DependencyProperty of type Int32


Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml [C++]



See also

Create(Object, PropertyChangedCallback)
Create(CreateDefaultValueCallback, PropertyChangedCallback)
Custom dependency properties
Dependency properties overview



© 2014 Microsoft