Ejemplo n.º 1
0
        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));
        }