diff --git a/Xamarin.Forms.Core.UnitTests/StyleSheets/StyleTests.cs b/Xamarin.Forms.Core.UnitTests/StyleSheets/StyleTests.cs index 6680dddef..0633c864a 100644 --- a/Xamarin.Forms.Core.UnitTests/StyleSheets/StyleTests.cs +++ b/Xamarin.Forms.Core.UnitTests/StyleSheets/StyleTests.cs @@ -17,6 +17,13 @@ namespace Xamarin.Forms.StyleSheets.UnitTests Internals.Registrar.RegisterAll(new Type[0]); } + [TearDown] + public void TearDown() + { + Device.PlatformServices = null; + Application.ClearCurrent(); + } + [Test] public void PropertiesAreApplied() { @@ -78,5 +85,17 @@ namespace Xamarin.Forms.StyleSheets.UnitTests var layout = new StackLayout(); Assert.That(layout.GetValue(TextElement.TextColorProperty), Is.EqualTo(Color.Default)); } + + [Test] + public void StyleSheetsOnAppAreApplied() + { + var app = new MockApplication(); + app.Resources.Add(StyleSheet.FromString("label{ color: red;}")); + var page = new ContentPage { + Content = new Label() + }; + app.MainPage = page; + Assert.That((page.Content as Label).TextColor, Is.EqualTo(Color.Red)); + } } } \ No newline at end of file diff --git a/Xamarin.Forms.Core/Element_StyleSheets.cs b/Xamarin.Forms.Core/Element_StyleSheets.cs index 7216e57ac..6d10fbd5f 100644 --- a/Xamarin.Forms.Core/Element_StyleSheets.cs +++ b/Xamarin.Forms.Core/Element_StyleSheets.cs @@ -41,8 +41,8 @@ namespace Xamarin.Forms return; var sheets = new List(); while (parent != null) { - var visualParent = parent as VisualElement; - var vpSheets = visualParent?.GetStyleSheets(); + var resourceProvider = parent as IResourcesProvider; + var vpSheets = resourceProvider?.GetStyleSheets(); if (vpSheets != null) sheets.AddRange(vpSheets); parent = parent.Parent;