是否有申报财产/ DependencyProperty的使用,如果它的双向绑定默认绑定的方法吗? [英] Is there a way to declare a Property/DependencyProperty to use TwoWay binding by default if its bound?

查看:213
本文介绍了是否有申报财产/ DependencyProperty的使用,如果它的双向绑定默认绑定的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控件,如文本框使用双向默认绑定

<TextBox Text="{Binding Text1}" />

然而,随着自定义用户控件,我需要像

However with Custom User Controls, I will need something like

<local:UserControl1 Text="{Binding Text1, Mode=TwoWay}" />

有没有一种方法我可以在属性设置绑定默认使用双向绑定?

Is there a way I can set bindings on a property to use TwoWay Bindings by default?

推荐答案

在财产申报,使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.windows.frameworkpropertymetadataoptions(VS.90).aspx\"相对=nofollow> FrameworkPropertyMetadataOptions.BindsTwoWayByDefault

When you declare property, use FrameworkPropertyMetadataOptions.BindsTwoWayByDefault.

public DependencyProperty SomeProperty =
    DependencyProperty.Register("Some", typeof(bool), typeof(Window1),
        new FrameworkPropertyMetadata(default(bool),
            FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

这篇关于是否有申报财产/ DependencyProperty的使用,如果它的双向绑定默认绑定的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆