【发布时间】:2010-08-09 14:16:30
【问题描述】:
我正在使用自定义默认按钮附加行为(定义如下: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); }
...
}
我应该如何在代码中为此创建绑定?
谢谢,
标记
【问题讨论】:
标签: binding silverlight-3.0 attachedbehaviors