我在包含文本框的Silverlight应用程序中有两个用户控件(1),当我开始在其中一个文本框中书写时,如何同步这些文本框。
答案 0 :(得分:0)
在每个控件中创建一个dependency property,用于更改文本框的值,然后将控件绑定到另一个的值。
例如
public static readonly DependencyProperty InnerTextProperty=
DependencyProperty.Register(
"InnerText", typeof(string),
new PropertyMetadata(false, OnTextInput) );
public bool InnerText
{
get { return (bool)GetValue(InnerTextProperty); }
set { SetValue(InnerTextProperty, value); }
}
private static void OnTextInput(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
YourControl c = obj as YourControl
if(c != null)
{
c._innerTextBox.Text = e.Value;
}
}