コード例 #1
0
ファイル: ResourcesLoader.cs プロジェクト: zhamppx97/maui
        public T CreateFromResource <T>(string resourcePath, Assembly assembly, IXmlLineInfo lineInfo) where T : new()
        {
            var rd = new T();

            var resourceLoadingResponse = Maui.Controls.Internals.ResourceLoader.ResourceProvider2?.Invoke(new Maui.Controls.Internals.ResourceLoader.ResourceLoadingQuery
            {
                AssemblyName = assembly.GetName(),
                ResourcePath = resourcePath,
                Instance     = rd,
            });

            var alternateResource = resourceLoadingResponse?.ResourceContent;

            if (alternateResource != null)
            {
                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))
                {
                    rd.LoadFromXaml(reader.ReadToEnd(), assembly);
                    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, string xaml)
 {
     XamlLoader.Load(view, xaml);
     return(view);
 }
コード例 #4
0
 public static TXaml LoadFromXaml <TXaml>(this TXaml view, Type callingType)
 {
     XamlLoader.Load(view, callingType);
     return(view);
 }