【发布时间】:2013-02-21 13:57:27
【问题描述】:
我在 Silverlight 应用程序中有两个包含文本框的用户控件 (1),当我开始在其中一个文本框中写入时,如何同步这些文本框。
【问题讨论】:
-
你想要实现什么,一个更新另一个?或者他们有相同的内容?
-
他们应该有相同的内容。
标签: silverlight synchronization
我在 Silverlight 应用程序中有两个包含文本框的用户控件 (1),当我开始在其中一个文本框中写入时,如何同步这些文本框。
【问题讨论】:
标签: silverlight synchronization
在每个控件中创建一个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;
}
}
【讨论】: