Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 2.9 KB

propertymetadata_create_581724777.md

File metadata and controls

46 lines (33 loc) · 2.9 KB
-api-id -api-type
M:Windows.UI.Xaml.PropertyMetadata.Create(Windows.UI.Xaml.CreateDefaultValueCallback)
winrt method

Windows.UI.Xaml.PropertyMetadata.Create

-description

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

-parameters

-param createDefaultValueCallback

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

-returns

The newly created dependency property metadata.

-remarks

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.

-examples

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

-see-also

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