コード例 #1
0
        public ResourceDictionary CreateResourceDictionary(string resourcePath, Assembly assembly, IXmlLineInfo lineInfo)
        {
            var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(assembly, resourcePath);

            if (resourceId == null)
            {
                throw new XamlParseException($"Resource '{resourcePath}' not found.", lineInfo);
            }

            var alternateResource = Xamarin.Forms.Internals.ResourceLoader.ResourceProvider?.Invoke(resourcePath);

            if (alternateResource != null)
            {
                var rd = new ResourceDictionary();
                rd.LoadFromXaml(alternateResource);
                return(rd);
            }

            using (var stream = assembly.GetManifestResourceStream(resourceId)) {
                if (stream == null)
                {
                    throw new XamlParseException($"No resource found for '{resourceId}'.", lineInfo);
                }
                using (var reader = new StreamReader(stream)) {
                    var rd = new ResourceDictionary();
                    rd.LoadFromXaml(reader.ReadToEnd());
                    return(rd);
                }
            }
        }
コード例 #2
0
 public ResourceDictionary CreateResourceDictionary(string resourceID, Assembly assembly, IXmlLineInfo lineInfo)
 {
     using (var stream = assembly.GetManifestResourceStream(resourceID)) {
         if (stream == null)
         {
             throw new XamlParseException($"No resource found for '{resourceID}'.", lineInfo);
         }
         using (var reader = new StreamReader(stream)) {
             var rd = new ResourceDictionary();
             rd.LoadFromXaml(reader.ReadToEnd());
             return(rd);
         }
     }
 }