开发者

How to set metadata options without setting a default value?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜