I am trying to bind two properties from two different object that both implements INotifyPropertyChanged
in code:
public class ClassA : INotifyPropertyChanged
{
// leaving out the INotifyPropertyChanged Members for brevity
public string Status
{
get { return _Status; }
set { _Status = value; RaiseChanged("Status"); }
}
}
public class ClassB : INotifyPropertyChanged
{
// leaving out the INotifyPropertyChanged Members for brevity
public string Status
{
get { return _Status; }
set { _Status = value; RaiseChanged("Status"); }
}
}
Is there a way I can bind these two properties in code together something like I would do if one of them was a 'proper' dependency property? Something like this?
ClassA classA = new ClassA();
ClassB classB = new ClassB();
Binding bind = new Binding("Status");
bind.Source = classA;
classB.SetBinding(ClassB.StatusProperty, bind);
Thanks!
Late response, but...KISS:
ClassA classA = new ClassA();
ClassB classB = new ClassB();
classA.PropertyChanged += (s, e) => {
if (e.PropertyName == "Status")
classB.Status = classA.Status;
};
Voila, "binding" between INPC objects :) You can easily create a very simple helper class that does this for you with a single method call if you plan to do this often.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With