Esempio n. 1
0
        static string GetXamlForType(Type type, object instance, out bool useDesignProperties)
        {
            useDesignProperties = false;
            //the Previewer might want to provide it's own xaml for this... let them do that
            //the check at the end is preferred (using ResourceLoader). keep this until all the previewers are updated

            string xaml;

#pragma warning disable 0618
            if (ResourceLoader.ResourceProvider2 == null && (xaml = Internals.XamlLoader.XamlFileProvider?.Invoke(type)) != null)
            {
                return(xaml);
            }
#pragma warning restore 0618

            var assembly   = type.GetTypeInfo().Assembly;
            var resourceId = XamlResourceIdAttribute.GetResourceIdForType(type);

            var rlr = ResourceLoader.ResourceProvider2?.Invoke(new ResourceLoader.ResourceLoadingQuery {
                AssemblyName = assembly.GetName(),
                ResourcePath = XamlResourceIdAttribute.GetPathForType(type),
                Instance     = instance,
            });
            var alternateXaml = rlr?.ResourceContent;

            if (alternateXaml != null)
            {
                useDesignProperties = rlr.UseDesignProperties;
                return(alternateXaml);
            }

            if (resourceId == null)
            {
                return(LegacyGetXamlForType(type));
            }

            using (var stream = assembly.GetManifestResourceStream(resourceId)) {
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream))
                        xaml = reader.ReadToEnd();
                }
                else
                {
                    xaml = null;
                }
            }

            return(xaml);
        }
Esempio n. 2
0
        static string GetXamlForType(Type type)
        {
            //the Previewer might want to provide it's own xaml for this... let them do that
            //the check at the end is preferred (using ResourceLoader). keep this until all the previewers are updated

            string xaml;

#pragma warning disable 0618
            if (ResourceLoader.ResourceProvider == null && (xaml = Internals.XamlLoader.XamlFileProvider?.Invoke(type)) != null)
            {
                return(xaml);
            }
#pragma warning restore 0618

            var assembly   = type.GetTypeInfo().Assembly;
            var resourceId = XamlResourceIdAttribute.GetResourceIdForType(type);

            var alternateXaml = ResourceLoader.ResourceProvider?.Invoke(assembly.GetName(), XamlResourceIdAttribute.GetPathForType(type));
            if (alternateXaml != null)
            {
                return(alternateXaml);
            }

            if (resourceId == null)
            {
                return(LegacyGetXamlForType(type));
            }

            using (var stream = assembly.GetManifestResourceStream(resourceId)) {
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream))
                        xaml = reader.ReadToEnd();
                }
                else
                {
                    xaml = null;
                }
            }

            return(xaml);
        }