2014-10-07 42 views
0

我們有一個自定義TextBox(繼承TextBox),並且我們希望將TextProperty的Binding的UpdateSourceTrigger值更改爲Explicit。在Silverlight中,只有三個值是Default,Explicit和PropertyChanged。更改Silverlight中所有TextBox的默認UpdateSourceTrigegr值

是否有任何常見的方法可以從控制代碼中完成它?

+0

任何代碼段或鏈接指導我? – Harsha 2014-10-07 18:41:46

回答

0

我不這麼認爲。
我這個實驗:

private void CustomTextBox1_OnLoaded(object sender, RoutedEventArgs e) 
    { 
     TextBox tb = sender as TextBox; 
     if (tb != null) 
     { 
      var b = tb.GetBindingExpression(TextBox.TextProperty); 
      var p = b.ParentBinding; 
      p.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; /* ERROR */ 

     } 
    } 

就行了標有「錯誤」引發了異常:Binding cannot be changed after it has been used.我不知道你怎麼能拿Text屬性的綁定任何較早。
在xaml中設置它有什麼問題?