【问题标题】:DependencyProperty with TwoWay Binding具有双向绑定的 DependencyProperty
【发布时间】:2011-01-08 04:09:06
【问题描述】:

我有一个高度自定义的编辑控件,它继承了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.
}

请帮忙。

【问题讨论】:

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


    【解决方案1】:

    使用可以在你的Binding语句中使用UpdateSourceTrigger=Explicit,将属性更新的控制权掌握在你的手中。

    查看Thread

    【讨论】:

      猜你喜欢
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-03
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多