Defines behavior aspects of a dependency property, including conditions it was registered with. For more info on how PropertyMetadata is used for dependency properties, see Custom dependency properties.
Inheritance
- Object
- PropertyMetadata
Syntax
Attributes
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.UI.Xaml.IPropertyMetadataStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
- WebHostHiddenAttribute()
Members
The PropertyMetadata class has these types of members:
Constructors
The PropertyMetadata class has these constructors.
| Constructor | Description |
|---|---|
| PropertyMetadata(Object) | Initializes a new instance of the PropertyMetadata class, using a property default value. |
| PropertyMetadata(Object, PropertyChangedCallback) | Initializes a new instance of the PropertyMetadata class, using a property default value and callback reference. |
Methods
The PropertyMetadata class has these methods. It also inherits methods from the Object class.
| Method | Description |
|---|---|
| Create(CreateDefaultValueCallback) | Creates a PropertyMetadata value, specifying a callback that establishes a 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) | Creates a PropertyMetadata value, specifying a fixed default value for a dependency property. |
| Create(Object, PropertyChangedCallback) | Creates a PropertyMetadata value, specifying a fixed default value for a dependency property, and a property-changed callback. |
Properties
The PropertyMetadata class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Gets a reference to the callback method that provides a default property value. | |
| Read-only | Gets the default value for the dependency property. |
Remarks
Defining a PropertyMetadata instance is part of the scenario for defining a custom dependency property. For info and examples, see Custom dependency properties.
A PropertyMetadata value represents two aspects of dependency property behavior:
- Provides a default value, which is used as the value of the property unless the owner type specifically initializes the value, or the value is set by user code or other mechanisms.
- References a callback that is invoked if the dependency property system detects that the dependency property has changed.
If your PropertyMetadata includes a property-changed callback reference, that method must be a static method of the class that exposes the DependencyProperty identifier where that PropertyMetadata is applied. How to write this method is described in Custom dependency properties and also the reference topic for the PropertyChangedCallback delegate.
Note Once created, a PropertyMetadata instance doesn't have a property that can be used to find the callback or even to determine the callback's method name. That information is considered an implementation detail of a dependency property and only the dependency property system itself needs to be able to invoke that method.
Instantiating a PropertyMetadata value
There are two methods that can instantiate a PropertyMetadata instance: a constructor, and a static PropertyMetadata.Create method. Each of these methods has multiple signatures. It's more common to use the constructors. However, you must use PropertyMetadata.Create if you want the default value mechanism for your dependency property to be thread-safe. For more info, see the "Property metadata for a custom dependency property" section of the Custom dependency properties topic.
Examples
This example calls the PropertyMetadata(Object) constructor, which creates a PropertyMetadata that reports a default value for a DependencyProperty. The PropertyMetadata is then used for an attached property registration when RegisterAttached is called.
public abstract class AquariumServices : DependencyObject
{
public enum Bouyancy {Floats,Sinks,Drifts}
public static readonly DependencyProperty BouyancyProperty = DependencyProperty.RegisterAttached(
"Bouyancy",
typeof(Bouyancy),
typeof(AquariumServices),
new PropertyMetadata(Bouyancy.Floats)
);
public static void SetBouyancy(DependencyObject element, Bouyancy value)
{
element.SetValue(BouyancyProperty, value);
}
public static Bouyancy GetBouyancy(DependencyObject element)
{
return (Bouyancy)element.GetValue(BouyancyProperty);
}
}
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps only] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps only] |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 1/31/2013