Udostępnij za pośrednictwem


PropertyMetadata.Create Method

Definition

Overloads

Create(CreateDefaultValueCallback)

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

Create(Object)

Creates a PropertyMetadata value, specifying a fixed default value for a dependency property.

Create(CreateDefaultValueCallback, PropertyChangedCallback)

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

Create(Object, PropertyChangedCallback)

Creates a PropertyMetadata value, specifying a fixed default value for a dependency property, and a property-changed callback.

Create(CreateDefaultValueCallback)

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

[Windows.Foundation.Metadata.Overload("CreateWithFactory")]
public static PropertyMetadata Create(CreateDefaultValueCallback createDefaultValueCallback);
function create(createDefaultValueCallback)
Public Shared Function Create (createDefaultValueCallback As CreateDefaultValueCallback) As PropertyMetadata

Parameters

createDefaultValueCallback
CreateDefaultValueCallback

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

Returns

The newly created dependency property metadata.

Attributes

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

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.

See also

Applies to

Create(Object)

Creates a PropertyMetadata value, specifying a fixed default value for a dependency property.

/// [Windows.Foundation.Metadata.DefaultOverload]
/// [Windows.Foundation.Metadata.Overload("CreateWithDefaultValue")]
 static PropertyMetadata Create(IInspectable const& defaultValue);
[Windows.Foundation.Metadata.DefaultOverload]
[Windows.Foundation.Metadata.Overload("CreateWithDefaultValue")]
public static PropertyMetadata Create(object defaultValue);
function create(defaultValue)
Public Shared Function Create (defaultValue As Object) As PropertyMetadata

Parameters

defaultValue
Object

IInspectable

The dependency property default value to apply.

Returns

The newly created dependency property metadata.

Attributes

See also

Applies to

Create(CreateDefaultValueCallback, PropertyChangedCallback)

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

[Windows.Foundation.Metadata.Overload("CreateWithFactoryAndCallback")]
public static PropertyMetadata Create(CreateDefaultValueCallback createDefaultValueCallback, PropertyChangedCallback propertyChangedCallback);
function create(createDefaultValueCallback, propertyChangedCallback)
Public Shared Function Create (createDefaultValueCallback As CreateDefaultValueCallback, propertyChangedCallback As PropertyChangedCallback) As PropertyMetadata

Parameters

createDefaultValueCallback
CreateDefaultValueCallback

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

propertyChangedCallback
PropertyChangedCallback

A reference to the callback method that is invoked by the property system when a dependency property value changes.

Returns

The newly created dependency property metadata.

Attributes

See also

Applies to

Create(Object, PropertyChangedCallback)

Creates a PropertyMetadata value, specifying a fixed default value for a dependency property, and a property-changed callback.

[Windows.Foundation.Metadata.DefaultOverload]
[Windows.Foundation.Metadata.Overload("CreateWithDefaultValueAndCallback")]
public static PropertyMetadata Create(object defaultValue, PropertyChangedCallback propertyChangedCallback);
function create(defaultValue, propertyChangedCallback)
Public Shared Function Create (defaultValue As Object, propertyChangedCallback As PropertyChangedCallback) As PropertyMetadata

Parameters

defaultValue
Object

The dependency property default value to apply.

propertyChangedCallback
PropertyChangedCallback

A reference to the callback method that is invoked by the property system when a dependency property value changes.

Returns

The newly created dependency property metadata.

Attributes

See also

Applies to