Exemple #1
0
        private static bool ResolveAssemblyThemeResources(Assembly assembly, out ResourceDictionary value)
        {
            ThemeInfoAttribute themeInfoAttribute = assembly.FirstOrDefaultCustomAttributeCached <ThemeInfoAttribute>();

            if (themeInfoAttribute == null || themeInfoAttribute.GenericDictionaryLocation == ResourceDictionaryLocation.None)
            {
                value = null;
                return(false);
            }

            string themeResourcesAssemblyName = themeInfoAttribute.GenericDictionaryLocation == ResourceDictionaryLocation.SourceAssembly ? assembly.GetName().Name : String.Format("{0}.{1}", assembly.GetName().Name, ThemeName);

            value = (ResourceDictionary)EmbeddedResourceLoader.LoadResourceElement(Granular.Compatibility.Uri.CreateAbsoluteUri(String.Format("pack://application:,,,/{0};component/Themes/{1}.xaml", themeResourcesAssemblyName, ThemeNameAndColor)));
            return(true);
        }
        private bool TryResolveResource(object resourceKey, out object value)
        {
            value = null;

            if (!(resourceKey is IResourceKey) || ((IResourceKey)resourceKey).Assembly == null)
            {
                return(false);
            }

            Assembly           assembly           = ((IResourceKey)resourceKey).Assembly;
            ThemeInfoAttribute themeInfoAttribute = assembly.FirstOrDefaultCustomAttributeCached <ThemeInfoAttribute>();

            if (themeInfoAttribute == null || themeInfoAttribute.GenericDictionaryLocation == ResourceDictionaryLocation.None)
            {
                return(false);
            }

            string assemblyName = themeInfoAttribute.GenericDictionaryLocation == ResourceDictionaryLocation.SourceAssembly ? assembly.GetName().Name : String.Format("{0}.{1}", assembly.GetName().Name, ThemeName);

            ResourceDictionary resourceDictionary = (ResourceDictionary)EmbeddedResourceLoader.LoadResourceElement(assemblyName, String.Format("Themes/{0}.xaml", ThemeNameAndColor));

            return(resourceDictionary.TryGetValue(resourceKey, out value));
        }