3 using Tizen.NUI.StyleSheets;
4 using System.Reflection;
6 using Tizen.NUI.Binding;
8 namespace Tizen.NUI.Xaml
10 [ContentProperty(nameof(Style))]
11 // [ProvideCompiled("Tizen.NUI.Core.XamlC.StyleSheetProvider")]
12 internal sealed class StyleSheetExtension : IValueProvider
14 public string Style { get; set; }
15 public Uri Source { get; set; }
17 object IValueProvider.ProvideValue(IServiceProvider serviceProvider)
19 IXmlLineInfo lineInfo;
21 if (!string.IsNullOrEmpty(Style) && Source != null) {
22 lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
23 throw new XamlParseException($"StyleSheet can not have both a Source and a content", lineInfo);
27 lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
28 if (Source.IsAbsoluteUri)
29 throw new XamlParseException($"Source only accepts Relative URIs", lineInfo);
31 var rootObjectType = (serviceProvider.GetService(typeof(IRootObjectProvider)) as IRootObjectProvider)?.RootObject.GetType();
32 if (rootObjectType == null)
34 var rootTargetPath = XamlResourceIdAttribute.GetPathForType(rootObjectType);
35 var resourcePath = ResourceDictionary.RDSourceTypeConverter.GetResourcePath(Source, rootTargetPath);
36 var resString = DependencyService.Get<IResourcesLoader>()?.GetResource(resourcePath, rootObjectType.GetTypeInfo().Assembly, lineInfo);
37 return StyleSheet.FromString(resString);
40 if (!string.IsNullOrEmpty(Style)) {
41 using (var reader = new StringReader(Style))
42 return StyleSheet.FromReader(reader);
45 lineInfo = (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) as IXmlLineInfoProvider)?.XmlLineInfo;
46 throw new XamlParseException($"StyleSheet require either a Source or a content", lineInfo);