具有TwoWay绑定的DependencyProperty

时间:2010-01-22 11:00:51

标签: c# .net wpf data-binding dependency-properties

我有一个高度自定义的编辑控件,它继承了RichTextBox。我需要一种方法将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.
}

请帮忙。

1 个答案:

答案 0 :(得分:0)

use可以在Binding语句中使用UpdateSourceTrigger=Explicit并获得对手中属性更新的控制。

选中此Thread