Browse Source

Renamed Bind to SetValue

pull/4/head
grokys 12 years ago
parent
commit
153a0b7d06
  1. 16
      Perspex.UnitTests/PerspexObjectTests.cs
  2. 2
      Perspex.Windows/Window.cs
  3. 8
      Perspex/Controls/Button.cs
  4. 41
      Perspex/PerspexObject.cs

16
Perspex.UnitTests/PerspexObjectTests.cs

@ -232,38 +232,38 @@ namespace Perspex.UnitTests
}
[TestMethod]
public void Bind_Sets_Current_Value()
public void Binding_Sets_Current_Value()
{
Class1 target = new Class1();
Class1 source = new Class1();
source.SetValue(Class1.FooProperty, "initial");
target.Bind(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
target.SetValue(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
Assert.AreEqual("initial", target.GetValue(Class1.FooProperty));
}
[TestMethod]
public void Bind_Sets_Subsequent_Value()
public void Binding_Sets_Subsequent_Value()
{
Class1 target = new Class1();
Class1 source = new Class1();
source.SetValue(Class1.FooProperty, "initial");
target.Bind(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
target.SetValue(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
source.SetValue(Class1.FooProperty, "subsequent");
Assert.AreEqual("subsequent", target.GetValue(Class1.FooProperty));
}
[TestMethod]
public void Bind_Doesnt_Set_Value_After_Clear()
public void Binding_Doesnt_Set_Value_After_Clear()
{
Class1 target = new Class1();
Class1 source = new Class1();
source.SetValue(Class1.FooProperty, "initial");
target.Bind(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
target.SetValue(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
target.ClearValue(Class1.FooProperty);
source.SetValue(Class1.FooProperty, "newvalue");
@ -271,13 +271,13 @@ namespace Perspex.UnitTests
}
[TestMethod]
public void Bind_Doesnt_Set_Value_After_Reset()
public void Binding_Doesnt_Set_Value_After_Reset()
{
Class1 target = new Class1();
Class1 source = new Class1();
source.SetValue(Class1.FooProperty, "initial");
target.Bind(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
target.SetValue(Class1.FooProperty, source.GetObservable(Class1.FooProperty));
target.SetValue(Class1.FooProperty, "reset");
source.SetValue(Class1.FooProperty, "newvalue");

2
Perspex.Windows/Window.cs

@ -82,7 +82,7 @@ namespace Perspex.Windows
Border border = new Border();
border.Background = new Perspex.Media.SolidColorBrush(0xffffffff);
ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(Window.ContentProperty));
contentPresenter.SetValue(ContentPresenter.ContentProperty, this.GetObservable(Window.ContentProperty));
border.Content = contentPresenter;
return border;
}

8
Perspex/Controls/Button.cs

@ -13,12 +13,12 @@ namespace Perspex.Controls
protected override Visual DefaultTemplate()
{
Border border = new Border();
border.Bind(Border.BackgroundProperty, this.GetObservable(Button.BackgroundProperty));
border.Bind(Border.BorderBrushProperty, this.GetObservable(Button.BorderBrushProperty));
border.Bind(Border.BorderThicknessProperty, this.GetObservable(Button.BorderThicknessProperty));
border.SetValue(Border.BackgroundProperty, this.GetObservable(Button.BackgroundProperty));
border.SetValue(Border.BorderBrushProperty, this.GetObservable(Button.BorderBrushProperty));
border.SetValue(Border.BorderThicknessProperty, this.GetObservable(Button.BorderThicknessProperty));
border.Padding = new Thickness(3);
ContentPresenter contentPresenter = new ContentPresenter();
contentPresenter.Bind(ContentPresenter.ContentProperty, this.GetObservable(Button.ContentProperty));
contentPresenter.SetValue(ContentPresenter.ContentProperty, this.GetObservable(Button.ContentProperty));
border.Content = contentPresenter;
return border;
}

41
Perspex/PerspexObject.cs

@ -153,27 +153,6 @@ namespace Perspex
}
}
/// <summary>
/// Binds a property on this object to an observable.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="target">The target property.</param>
/// <param name="source">The observable.</param>
public void Bind<T>(PerspexProperty<T> target, IObservable<T> source)
{
Contract.Requires<NullReferenceException>(target != null);
Contract.Requires<NullReferenceException>(source != null);
this.ClearBinding(target);
IDisposable binding = source.Subscribe(value =>
{
this.SetValueImpl(target, value);
});
this.bindings.Add(target, binding);
}
/// <summary>
/// Clears a binding on a <see cref="PerspexProperty"/>, leaving the last bound value in
/// place.
@ -373,6 +352,26 @@ namespace Perspex
this.SetValue((PerspexProperty)property, value);
}
/// <summary>
/// Binds a <see cref="PerspexProperty"/> to an observable.
/// </summary>
/// <typeparam name="T">The type of the property.</typeparam>
/// <param name="property">The property.</param>
/// <param name="source">The observable.</param>
public void SetValue<T>(PerspexProperty<T> property, IObservable<T> source)
{
Contract.Requires<NullReferenceException>(property != null);
this.ClearBinding(property);
IDisposable binding = source.Subscribe(value =>
{
this.SetValueImpl(property, value);
});
this.bindings.Add(property, binding);
}
/// <summary>
/// Called when a property is changed on the current <see cref="InheritanceParent"/>.
/// </summary>

Loading…
Cancel
Save