From 153a0b7d06997e53f0d3bf35efc3e735ed29bf17 Mon Sep 17 00:00:00 2001 From: grokys Date: Sun, 2 Feb 2014 01:55:53 +0100 Subject: [PATCH] Renamed Bind to SetValue --- Perspex.UnitTests/PerspexObjectTests.cs | 16 +++++----- Perspex.Windows/Window.cs | 2 +- Perspex/Controls/Button.cs | 8 ++--- Perspex/PerspexObject.cs | 41 ++++++++++++------------- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/Perspex.UnitTests/PerspexObjectTests.cs b/Perspex.UnitTests/PerspexObjectTests.cs index e6ddeec82d..8889fb2a05 100644 --- a/Perspex.UnitTests/PerspexObjectTests.cs +++ b/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"); diff --git a/Perspex.Windows/Window.cs b/Perspex.Windows/Window.cs index 813fd69087..f0ac4892c7 100644 --- a/Perspex.Windows/Window.cs +++ b/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; } diff --git a/Perspex/Controls/Button.cs b/Perspex/Controls/Button.cs index 8b76c6387b..5806086e70 100644 --- a/Perspex/Controls/Button.cs +++ b/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; } diff --git a/Perspex/PerspexObject.cs b/Perspex/PerspexObject.cs index 4c0378f2ed..9075e1ad80 100644 --- a/Perspex/PerspexObject.cs +++ b/Perspex/PerspexObject.cs @@ -153,27 +153,6 @@ namespace Perspex } } - /// - /// Binds a property on this object to an observable. - /// - /// The type of the property. - /// The target property. - /// The observable. - public void Bind(PerspexProperty target, IObservable source) - { - Contract.Requires(target != null); - Contract.Requires(source != null); - - this.ClearBinding(target); - - IDisposable binding = source.Subscribe(value => - { - this.SetValueImpl(target, value); - }); - - this.bindings.Add(target, binding); - } - /// /// Clears a binding on a , leaving the last bound value in /// place. @@ -373,6 +352,26 @@ namespace Perspex this.SetValue((PerspexProperty)property, value); } + /// + /// Binds a to an observable. + /// + /// The type of the property. + /// The property. + /// The observable. + public void SetValue(PerspexProperty property, IObservable source) + { + Contract.Requires(property != null); + + this.ClearBinding(property); + + IDisposable binding = source.Subscribe(value => + { + this.SetValueImpl(property, value); + }); + + this.bindings.Add(property, binding); + } + /// /// Called when a property is changed on the current . ///