From e83c2e06fd6173abe697fe7d2bc22a87035067ef Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 25 May 2015 20:07:24 +0200 Subject: [PATCH 1/2] Make sure bound property is registered. --- Perspex.Base/PerspexObject.cs | 8 ++++++++ Tests/Perspex.Base.UnitTests/PerspexObjectTests.cs | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/Perspex.Base/PerspexObject.cs b/Perspex.Base/PerspexObject.cs index 5fb57a7bac..f43bbcd9aa 100644 --- a/Perspex.Base/PerspexObject.cs +++ b/Perspex.Base/PerspexObject.cs @@ -574,6 +574,14 @@ namespace Perspex PriorityValue v; IDescription description = source as IDescription; + if (!this.IsRegistered(property)) + { + throw new InvalidOperationException(string.Format( + "Property '{0}' not registered on '{1}'", + property.Name, + this.GetType())); + } + if (!this.values.TryGetValue(property, out v)) { v = this.CreatePriorityValue(property); diff --git a/Tests/Perspex.Base.UnitTests/PerspexObjectTests.cs b/Tests/Perspex.Base.UnitTests/PerspexObjectTests.cs index 4577059964..0ceeaee616 100644 --- a/Tests/Perspex.Base.UnitTests/PerspexObjectTests.cs +++ b/Tests/Perspex.Base.UnitTests/PerspexObjectTests.cs @@ -355,6 +355,17 @@ namespace Perspex.Base.UnitTests Assert.Equal("initial", target.GetValue(Class1.FooProperty)); } + [Fact] + public void Bind_Throws_Exception_For_Unregistered_Property() + { + Class1 target = new Class1(); + + Assert.Throws(() => + { + target.Bind(Class2.BarProperty, Observable.Return("foo")); + }); + } + [Fact] public void Bind_Sets_Subsequent_Value() { From 268b34e4fc329bb110533ee29bed4af2206de8f0 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Mon, 25 May 2015 20:09:53 +0200 Subject: [PATCH 2/2] Make TextBlock properties attached properties. This is how they should've been all along, except PerspexObject.Bind didn't check that a property was registered before binding to it, so it went unnoticed. --- Perspex.Controls/TextBlock.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Perspex.Controls/TextBlock.cs b/Perspex.Controls/TextBlock.cs index 3ed165e624..7c03c3fdd7 100644 --- a/Perspex.Controls/TextBlock.cs +++ b/Perspex.Controls/TextBlock.cs @@ -17,19 +17,19 @@ namespace Perspex.Controls Border.BackgroundProperty.AddOwner(); public static readonly PerspexProperty FontFamilyProperty = - PerspexProperty.Register("FontFamily", inherits: true); + PerspexProperty.RegisterAttached("FontFamily", inherits: true); public static readonly PerspexProperty FontSizeProperty = - PerspexProperty.Register("FontSize", inherits: true); + PerspexProperty.RegisterAttached("FontSize", inherits: true); public static readonly PerspexProperty FontStyleProperty = - PerspexProperty.Register("FontStyle", inherits: true); + PerspexProperty.RegisterAttached("FontStyle", inherits: true); public static readonly PerspexProperty FontWeightProperty = - PerspexProperty.Register("FontWeight", inherits: true, defaultValue: FontWeight.Normal); + PerspexProperty.RegisterAttached("FontWeight", inherits: true, defaultValue: FontWeight.Normal); public static readonly PerspexProperty ForegroundProperty = - PerspexProperty.Register("Foreground", new SolidColorBrush(0xff000000), inherits: true); + PerspexProperty.RegisterAttached("Foreground", new SolidColorBrush(0xff000000), inherits: true); public static readonly PerspexProperty TextProperty = PerspexProperty.Register("Text");