public void StyleSheetsOnAppAreApplied() { var app = new MockApplication(); app.Resources.Add(StyleSheet.FromString("label{ color: red;}")); var page = new ContentPage { Content = new Label() }; app.LoadPage(page); Assert.That((page.Content as Label).TextColor, Is.EqualTo(Colors.Red)); }
public void StyleSheetsOnAppAreAppliedBeforePageStyleSheet() { var app = new MockApplication(); app.Resources.Add(StyleSheet.FromString("label{ color: white; background-color: blue; }")); var page = new ContentPage { Content = new Label() }; page.Resources.Add(StyleSheet.FromString("label{ color: red; }")); app.LoadPage(page); Assert.That((page.Content as Label).TextColor, Is.EqualTo(Colors.Red)); Assert.That((page.Content as Label).BackgroundColor, Is.EqualTo(Colors.Blue)); }
public void StyleSheetsOnChildAreReAppliedWhenParentStyleSheetAdded() { var app = new MockApplication(); var page = new ContentPage { Content = new Label() }; page.Resources.Add(StyleSheet.FromString("label{ color: red; }")); app.MainPage = page; Assert.That((page.Content as Label).TextColor, Is.EqualTo(Color.Red)); app.Resources.Add(StyleSheet.FromString("label{ color: white; background-color: blue; }")); Assert.That((page.Content as Label).BackgroundColor, Is.EqualTo(Color.Blue)); Assert.That((page.Content as Label).TextColor, Is.EqualTo(Color.Red)); }
public void StyleSheetsOnSubviewAreAppliedBeforePageStyleSheet() { var app = new MockApplication(); app.Resources.Add(StyleSheet.FromString("label{ color: white; }")); var label = new Label(); label.Resources.Add(StyleSheet.FromString("label{color: yellow;}")); var page = new ContentPage { Content = label }; page.Resources.Add(StyleSheet.FromString("label{ color: red; }")); app.LoadPage(page); Assert.That((page.Content as Label).TextColor, Is.EqualTo(Colors.Yellow)); }
object IValueProvider.ProvideValue(IServiceProvider serviceProvider) { IXmlLineInfo lineInfo; if (!string.IsNullOrEmpty(Style) && Source != null) { lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; throw new XamlParseException($"StyleSheet can not have both a Source and a content", lineInfo); } if (Source != null) { lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; if (Source.IsAbsoluteUri) { throw new XamlParseException($"Source only accepts Relative URIs", lineInfo); } var rootObjectType = (serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider)?.RootObject.GetType(); if (rootObjectType == null) { return(null); } var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType); var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Source, rootTargetPath); var resString = DependencyService.Get <IResourcesLoader>()?.GetResource(resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo); return(StyleSheet.FromString(resString)); } if (!string.IsNullOrEmpty(Style)) { using (var reader = new StringReader(Style)) return(StyleSheet.FromReader(reader)); } lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo; throw new XamlParseException($"StyleSheet require either a Source or a content", lineInfo); }