diff --git a/Ooui/Style.cs b/Ooui/Style.cs index e793829..2c6fabb 100644 --- a/Ooui/Style.cs +++ b/Ooui/Style.cs @@ -17,12 +17,17 @@ namespace Ooui set => SetProperty ("background-color", value); } + public Value BackgroundImage { + get => GetProperty ("background-image"); + set => SetProperty ("background-image", value); + } + private Value GetProperty (string propertyName) { lock (properties) { Value p; if (!properties.TryGetValue (propertyName, out p)) { - p = new Value (); + p = "inherit"; properties[propertyName] = p; } return p; @@ -31,13 +36,14 @@ namespace Ooui private void SetProperty (string propertyName, Value value) { + var safeValue = value ?? "inherit"; lock (properties) { Value old; if (properties.TryGetValue (propertyName, out old)) { - if (EqualityComparer.Default.Equals (old, value)) + if (EqualityComparer.Default.Equals (old, safeValue)) return; } - properties[propertyName] = value; + properties[propertyName] = safeValue; } PropertyChanged?.Invoke (this, new PropertyChangedEventArgs (propertyName)); } diff --git a/Tests/StyleTests.cs b/Tests/StyleTests.cs index 2915d29..a6919af 100644 --- a/Tests/StyleTests.cs +++ b/Tests/StyleTests.cs @@ -8,6 +8,23 @@ namespace Tests [TestClass] public class StyleTests { + [TestMethod] + public void DefaultIsInherit () + { + var s = new Style (); + Assert.AreEqual ("inherit", s.BackgroundColor); + } + + [TestMethod] + public void NullMakesInherit () + { + var s = new Style (); + s.BackgroundColor = "red"; + Assert.AreEqual ("red", s.BackgroundColor); + s.BackgroundColor = null; + Assert.AreEqual ("inherit", s.BackgroundColor); + } + [TestMethod] public void ChangedWhen () {