Phil Gan
Phil Gan

Reputation: 2863

How to set metadata options without setting a default value?

When registering a dependency property how do I set metadata options without setting a default value?

Upvotes: 1

Views: 224

Answers (2)

LPL
LPL

Reputation: 17083

You could do this with Object Initializer

public static readonly DependencyProperty MyDependencyProperty =
    DependencyProperty.Register("MyDependency",
                                typeof(propertyType),
                                typeof(ownerType),
                                new FrameworkPropertyMetadata {
                                    BindsTwoWayByDefault = true,
                                    PropertyChangedCallback = OnPropertyChanged,
                                    ... etc ...
                                });

Upvotes: 1

Haris Hasan
Haris Hasan

Reputation: 30107

There are four constructors available for PropertyMetadata which you can find here. You can use the third one which doesn't take any default value parameter.

PropertyMetadata(PropertyChangedCallback)

public static readonly DependencyProperty SomeProperty =    DependencyProperty.Register("SomeName", typeof(string), typeof(SomeClass),
                                                                      new PropertyMetadata(SomeChangedCallback),
                                                                      SomeValidateCallback);

Upvotes: 1

Related Questions