示例#1
0
        public T CreateFromResource <T>(string resourcePath, Assembly assembly, IXmlLineInfo lineInfo) where T : new()
        {
            var resourceLoadingResponse = Forms.Internals.ResourceLoader.ResourceProvider2?.Invoke(new Forms.Internals.ResourceLoader.ResourceLoadingQuery {
                AssemblyName = assembly.GetName(),
                ResourcePath = resourcePath
            });

            var alternateResource = resourceLoadingResponse?.ResourceContent;

            if (alternateResource != null)
            {
                var rd = new T();
                XamlLoader.Load(rd, alternateResource, resourceLoadingResponse.UseDesignProperties);
                return(rd);
            }

            var resourceId = XamlResourceIdAttribute.GetResourceIdForPath(assembly, resourcePath);

            if (resourceId == null)
            {
                throw new XamlParseException($"Resource '{resourcePath}' not found.", 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 T();
                    rd.LoadFromXaml(reader.ReadToEnd());
                    return(rd);
                }
            }
        }
示例#2
0
 internal static TXaml LoadFromXaml <TXaml>(this TXaml view, string xaml, Assembly rootAssembly)
 {
     XamlLoader.Load(view, xaml, rootAssembly);
     return(view);
 }
示例#3
0
 public static TXaml LoadFromXaml <TXaml>(this TXaml view, Type callingType)
 {
     XamlLoader.Load(view, callingType);
     return(view);
 }
示例#4
0
 public static TXaml LoadFromXaml <TXaml>(this TXaml view, string xaml)
 {
     XamlLoader.Load(view, xaml);
     return(view);
 }
示例#5
0
 public static void LoadFromXaml(this object view, string xaml)
 {
     XamlLoader.Load(view, xaml);
 }