我有多个 C# 对象需要在属性更改时得到通知(该属性属于 FrameworkElement,如按钮或列表框)。
我谦虚地测试了使用 SetBinding 方法绑定单个对象,如下所示:
// DepOb is my FrameworkElement
// DepPropDesc is the DependencyPropertyDescriptor
System.Windows.Data.Binding bind = new System.Windows.Data.Binding();
bind.Source = this;
bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
bind.Path = new PropertyPath("Value");
bind.Mode = ob.BindingMode;
DepOb.SetBinding(DepPropDesc.DependencyProperty, bind);
但是当我创建第二个对象并绑定它时,不再调用第一个对象。如果我在两行之间阅读,该方法会设置绑定,所以前一个被刷新,对吧?
MSDN 谈到了一个“多绑定”对象,但我不知道如何“获取”存储在多绑定中的先前绑定,以便我可以将新绑定附加到它。
我将继续搜索,但我想看看这里是否有人对我可能做错了什么有想法。
提前致谢!
塞布