diff --git a/Perspex.UnitTests/Perspex.UnitTests.csproj b/Perspex.UnitTests/Perspex.UnitTests.csproj index 33ff73f5aa..02f45f0230 100644 --- a/Perspex.UnitTests/Perspex.UnitTests.csproj +++ b/Perspex.UnitTests/Perspex.UnitTests.csproj @@ -65,6 +65,7 @@ + diff --git a/Perspex.UnitTests/StyleTests.cs b/Perspex.UnitTests/StyleTests.cs new file mode 100644 index 0000000000..3bfde8e957 --- /dev/null +++ b/Perspex.UnitTests/StyleTests.cs @@ -0,0 +1,91 @@ +// ----------------------------------------------------------------------- +// +// Copyright 2014 MIT Licence. See licence.md for more information. +// +// ----------------------------------------------------------------------- + +namespace Perspex.UnitTests +{ + using System; + using System.Collections.Generic; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Perspex.Controls; + + [TestClass] + public class StyleTests + { + [TestMethod] + public void Style_Should_Update_And_Restore_Value() + { + Style style = new Style + { + Selector = x => x.Select().Class("foo"), + Setters = new[] + { + new Setter + { + Property = TextBlock.TextProperty, + Value = "Foo", + } + }, + }; + + TextBlock textBlock = new TextBlock + { + Text = "Original", + }; + + style.Attach(textBlock); + Assert.AreEqual("Original", textBlock.Text); + textBlock.Classes.Add("foo"); + Assert.AreEqual("Foo", textBlock.Text); + textBlock.Classes.Remove("foo"); + Assert.AreEqual("Original", textBlock.Text); + } + + [TestMethod] + public void Later_Styles_Should_Override_Earlier() + { + Style style1 = new Style + { + Selector = x => x.Select().Class("foo"), + Setters = new[] + { + new Setter + { + Property = TextBlock.TextProperty, + Value = "Foo", + } + }, + }; + + Style style2 = new Style + { + Selector = x => x.Select().Class("foo"), + Setters = new[] + { + new Setter + { + Property = TextBlock.TextProperty, + Value = "Bar", + } + }, + }; + + TextBlock textBlock = new TextBlock + { + Text = "Original", + }; + + List values = new List(); + textBlock.GetObservable(TextBlock.TextProperty).Subscribe(x => values.Add(x)); + + style1.Attach(textBlock); + style2.Attach(textBlock); + textBlock.Classes.Add("foo"); + textBlock.Classes.Remove("foo"); + + CollectionAssert.AreEqual(new[] { "Original", "Bar", "Original" }, values); + } + } +} diff --git a/Perspex/Setter.cs b/Perspex/Setter.cs index e9e1743dd2..f86a7d5a89 100644 --- a/Perspex/Setter.cs +++ b/Perspex/Setter.cs @@ -63,7 +63,7 @@ namespace Perspex internal SetterSubject CreateSubject(Control control) { - object oldValue = control.ExtractBinding(this.Property) ?? control.GetValue(this.Property); + object oldValue = control.GetValue(this.Property); return new SetterSubject(control, this.Value, oldValue); } }