DependencyProperty with TwoWay Binding
I have a highly customized Edit control which inher开发者_开发知识库its 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.
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.
Check this Thread
精彩评论