.net - 有没有一种方法可以声明 Property/DependencyProperty 在绑定(bind)时默认使用 TwoWay 绑定(bind)?

标签 .net wpf binding user-controls

TextBox这样的控件默认使用TwoWay绑定(bind)

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

但是对于自定义用户控件,我需要像

这样的东西
<local:UserControl1 Text="{Binding Text1, Mode=TwoWay}" />

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

最佳答案

声明属性(property)时,使用FrameworkPropertyMetadataOptions.BindsTwoWayByDefault .

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

关于.net - 有没有一种方法可以声明 Property/DependencyProperty 在绑定(bind)时默认使用 TwoWay 绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4237454/

相关文章:

c# - 如何使用Lambda表达式选择特定项目?

c# - 如何以编程方式确定 GAC 中是否安装了 .NET 程序集?

angularjs - Angular JS 1.3+ 具有三元条件的 ng-bind 一次性绑定(bind)

java - 在 Spring 2.5 中使用基于注释的 Controller 形成绑定(bind) HashMap

wpf - MVVM WPF 数据绑定(bind)复选框不会针对选中和未选中状态向 ViewModel 触发事件

c# - WPF - 交换 ContentControl(重新链接元素???)

c# - Azure 函数无法访问 mscorelib.dll 访问被拒绝

c# - 我可以扩展 .Net 中的所有对象(不仅仅是 winforms 控件)以具有标记属性吗?

c# - 获取控件的形状作为 Geometry

c# - DataObject.GetDatapresent 与子类