开发者

How to set metadata options without setting a default value?

开发者 https://www.devze.com 2023-03-26 03:21 出处:网络
When registering a dependency property how do I set metadata o开发者_JAVA技巧ptions without setting a default value?You could do this with Object Initializer

When registering a dependency property how do I set metadata o开发者_JAVA技巧ptions without setting a default value?


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 ...
                                });


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消