Reputation: 2863
When registering a dependency property how do I set metadata options without setting a default value?
Upvotes: 1
Views: 224
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
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