Browse Source

Removed PerspexObject.BindTwoWay.

Instead use subjects and Bind.
pull/396/head
Steven Kirk 11 years ago
parent
commit
e08b9e3e4b
  1. 64
      src/Perspex.Base/PerspexObject.cs
  2. 30
      tests/Perspex.Base.UnitTests/PerspexObjectTests_Binding.cs

64
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
}
}
/// <summary>
/// Initiates a two-way binding between <see cref="PerspexProperty"/>s.
/// </summary>
/// <param name="property">The property on this object.</param>
/// <param name="source">The source object.</param>
/// <param name="sourceProperty">The property on the source object.</param>
/// <param name="priority">The priority of the binding.</param>
/// <returns>
/// A disposable which can be used to terminate the binding.
/// </returns>
/// <remarks>
/// The binding is first carried out from <paramref name="source"/> to this.
/// </remarks>
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)));
}
/// <summary>
/// Initiates a two-way binding between a <see cref="PerspexProperty"/> and an
/// <see cref="ISubject{Object}"/>.
/// </summary>
/// <param name="property">The property on this object.</param>
/// <param name="source">The subject to bind to.</param>
/// <param name="priority">The priority of the binding.</param>
/// <returns>
/// A disposable which can be used to terminate the binding.
/// </returns>
/// <remarks>
/// The binding is first carried out from <paramref name="source"/> to this.
/// </remarks>
public IDisposable BindTwoWay(
PerspexProperty property,
ISubject<object> 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));
}
/// <summary>
/// Forces the specified property to be revalidated.
/// </summary>

30
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()
{

Loading…
Cancel
Save