PropertyMetadata Constructors

Definition

Overloads

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.

PropertyMetadata(Object)

Initializes a new instance of the PropertyMetadata class, using a property default value.

C#
public PropertyMetadata(object defaultValue);

Parameters

defaultValue
Object

A default value for the property where this PropertyMetadata is applied.

Applies to

Windows App SDK 1.6 and other versions
Product Versions
Windows App SDK 0.8, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6

PropertyMetadata(Object, PropertyChangedCallback)

Initializes a new instance of the PropertyMetadata class, using a property default value and callback reference.

C#
public PropertyMetadata(object defaultValue, PropertyChangedCallback propertyChangedCallback);

Parameters

defaultValue
Object

A default value for the property where this PropertyMetadata is applied.

propertyChangedCallback
PropertyChangedCallback

A reference to the callback to call for property changed behavior.

Examples

This example shows usage of this constructor. OnLabelChanged refers to a delegate implementation for a PropertyChangedCallback (not shown). To see more code that puts this example in context, see Custom dependency properties.

C#
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(
  "Label",
  typeof(String),
  typeof(ImageWithLabelControl),
  new PropertyMetadata(null,new PropertyChangedCallback(OnLabelChanged))
);
C++
DependencyProperty^ ImageWithLabelControl::_LabelProperty = 
    DependencyProperty::Register("Label", 
    Platform::String::typeid,
    ImageWithLabelControl::typeid, 
    ref new PropertyMetadata(nullptr,
      ref new PropertyChangedCallback(&ImageWithLabelControl::OnLabelChanged))
    );

Remarks

If you want to establish a PropertyMetadata instance that has a property-changed callback method but not a default value, pass null for defaultValue.

If you pass a value for defaultValue, make sure that the type of that value is valid for the propertyType type from the dependency property's definition through the Register call. If you've created a type mismatch between registration parameter and metadata, the issue only manifests itself indirectly. You'll get runtime errors when you try to instantiate a type that has this dependency property value, you won't get any design-time or compile-time warning or error.

See also

Applies to

Windows App SDK 1.6 and other versions
Product Versions
Windows App SDK 0.8, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6