我正在使用自定义的默认按钮附加行为(如此处定义: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); }
...
}
我应该如何在代码中为此创建绑定?
谢谢,
马克