简体   繁体   English

具有双向绑定的DependencyProperty

[英]DependencyProperty with TwoWay Binding

I have a highly customized Edit control which inherits RichTextBox . 我有一个高度定制的Edit控件,该控件继承了RichTextBox I needed a way to bind a Value to this control, so I registered a new DependencyProperty , but I have trouble to code it like I need. 我需要一种将Value绑定到此控件的方法,所以我注册了一个新的DependencyProperty ,但是我很难像我需要的那样对其进行编码。

public static readonly DependencyProperty ValueProperty =
            DependencyProperty.Register("Value", typeof(string), typeof(XliffRichCellEditor),
            new PropertyMetadata(new PropertyChangedCallback(XliffRichCellEditor.OnValuePropertyChanged)));
public String Value
{
    get { return (String)this.GetValue(ValueProperty); }
    set { this.SetValue(ValueProperty, value); }
}

private static void OnValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    // Need to change Document in  RichTextBox when Binding Source is changed
    // But also ignore if the change comes from RichTextBox which is only updating
    // the DependencyProperty. In this case Binding Source should be updated.
}

Please help. 请帮忙。

use can use UpdateSourceTrigger=Explicit in your Binding statement and get the control of property updation in your hand. use可以在Binding语句中使用UpdateSourceTrigger=Explicit并获得对属性更新的控制权。

Check this Thread 检查该线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM