2
我正在使用自定義默認按鈕附加行爲(如此處定義:Silverlight 4 Default Button Service)。代碼綁定附加行爲
我能夠在XAML綁定成功這一點,但在嵌套的用戶控制,在後面的代碼下面不工作:
public partial class MyNestedUserContol{
/// a DP for storing the name of the default button, used in the ElementName binding
public string DefaultButton {
get { return (string)GetValue(DefaultButtonProperty); }
set { SetValue(DefaultButtonProperty, value); }
}
public static readonly DependencyProperty DefaultButtonProperty =
DependencyProperty.Register("DefaultButton", typeof(string), typeof(TeamReferenceFieldEditor), new PropertyMetadata(null));
...
private void CreateCustomControls(){
...
TextBox tb = new TextBox();
...
AddDefaultButtonBinding(tb);
...
}
private void AddDefaultButtonBinding(Control control) {
Binding binding = new Binding();
binding.ElementName = this.DefaultButton;
control.SetBinding(DefaultButtonService.DefaultButtonProperty, binding); }
...
}
我應該如何在代碼中創建這種情況的結合?
謝謝,
馬克