2013-02-21 42 views
0

我在Silverlight應用程序中包含兩個用戶控件,包含文本框(1),當我開始在其中一個文本框中寫入時,如何同步這些文本框。在Silverlight中同步

+0

什麼是你想實現的,即一個更新其他?或者他們有相同的內容? – Constanta 2013-02-21 14:04:00

+0

他們應該有相同的內容。 – 2013-02-21 14:05:22

回答

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; 
    } 

} 
+0

:感謝您的回覆,但可以請告訴我如何在兩個控件都在不同的用戶控件中創建依賴項屬性? – 2013-02-21 14:26:48

+0

非常感謝,我的問題解決了。 – 2013-02-21 14:40:40

+0

馬克回答如果你有機會! – tam 2013-02-21 14:46:25