diff --git a/src/Perspex.Base/PerspexObject.cs b/src/Perspex.Base/PerspexObject.cs index 5c4271a57d..5310651514 100644 --- a/src/Perspex.Base/PerspexObject.cs +++ b/src/Perspex.Base/PerspexObject.cs @@ -185,7 +185,8 @@ namespace Perspex sourceBinding.Source.Bind(sourceBinding.Property, this.GetObservable(binding.Property), binding.Priority); break; case BindingMode.TwoWay: - BindTwoWay(binding.Property, sourceBinding.Source, sourceBinding.Property); + var subject = sourceBinding.Source.GetSubject(sourceBinding.Property, sourceBinding.Priority); + this.Bind(binding.Property, subject, BindingMode.TwoWay, sourceBinding.Priority); break; } } @@ -480,67 +481,6 @@ namespace Perspex } } - /// - /// Initiates a two-way binding between s. - /// - /// The property on this object. - /// The source object. - /// The property on the source object. - /// The priority of the binding. - /// - /// A disposable which can be used to terminate the binding. - /// - /// - /// The binding is first carried out from to this. - /// - public IDisposable BindTwoWay( - PerspexProperty property, - PerspexObject source, - PerspexProperty sourceProperty, - BindingPriority priority = BindingPriority.LocalValue) - { - VerifyAccess(); - _propertyLog.Verbose( - "Bound two way {Property} to {Binding} with priority {Priority}", - property, - source, - priority); - - return new CompositeDisposable( - Bind(property, source.GetObservable(sourceProperty)), - source.Bind(sourceProperty, this.GetObservable(property))); - } - - /// - /// Initiates a two-way binding between a and an - /// . - /// - /// The property on this object. - /// The subject to bind to. - /// The priority of the binding. - /// - /// A disposable which can be used to terminate the binding. - /// - /// - /// The binding is first carried out from to this. - /// - public IDisposable BindTwoWay( - PerspexProperty property, - ISubject source, - BindingPriority priority = BindingPriority.LocalValue) - { - VerifyAccess(); - _propertyLog.Verbose( - "Bound two way {Property} to {Binding} with priority {Priority}", - property, - GetDescription(source), - priority); - - return new CompositeDisposable( - Bind(property, source), - this.GetObservable(property).Subscribe(source)); - } - /// /// Forces the specified property to be revalidated. /// diff --git a/tests/Perspex.Base.UnitTests/PerspexObjectTests_Binding.cs b/tests/Perspex.Base.UnitTests/PerspexObjectTests_Binding.cs index 6788e509e2..3e7ee6f86d 100644 --- a/tests/Perspex.Base.UnitTests/PerspexObjectTests_Binding.cs +++ b/tests/Perspex.Base.UnitTests/PerspexObjectTests_Binding.cs @@ -82,7 +82,7 @@ namespace Perspex.Base.UnitTests } [Fact] - public void Two_Way_Binding_Works() + public void Two_Way_Separate_Binding_Works() { Class1 obj1 = new Class1(); Class1 obj2 = new Class1(); @@ -143,34 +143,6 @@ namespace Perspex.Base.UnitTests Assert.Equal("third", obj2.GetValue(Class1.FooProperty)); } - [Fact] - public void BindTwoWay_Gets_Initial_Value_From_Source() - { - Class1 source = new Class1(); - Class1 target = new Class1(); - - source.SetValue(Class1.FooProperty, "initial"); - target.BindTwoWay(Class1.FooProperty, source, Class1.FooProperty); - - Assert.Equal("initial", target.GetValue(Class1.FooProperty)); - } - - [Fact] - public void BindTwoWay_Updates_Values() - { - Class1 source = new Class1(); - Class1 target = new Class1(); - - source.SetValue(Class1.FooProperty, "first"); - target.BindTwoWay(Class1.FooProperty, source, Class1.FooProperty); - - Assert.Equal("first", target.GetValue(Class1.FooProperty)); - source.SetValue(Class1.FooProperty, "second"); - Assert.Equal("second", target.GetValue(Class1.FooProperty)); - target.SetValue(Class1.FooProperty, "third"); - Assert.Equal("third", source.GetValue(Class1.FooProperty)); - } - [Fact] public void Local_Binding_Overwrites_Local_Value() {