-api-id | -api-type |
---|---|
M:Windows.UI.Xaml.PropertyMetadata.Create(Windows.UI.Xaml.CreateDefaultValueCallback) |
winrt method |
Creates a PropertyMetadata value, specifying a callback that establishes a default value for a dependency property.
A reference to the callback method that provides a default property value.
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
}
})
Create(Object), Create(Object, PropertyChangedCallback), Create(CreateDefaultValueCallback, PropertyChangedCallback), Custom dependency properties, Dependency properties overview