示例#1
0
        public static bool IsThemeDictionary(ResourceDictionary resourceDictionary)
        {
            if (resourceDictionary is null)
            {
                throw new ArgumentNullException(nameof(resourceDictionary));
            }

            var source = resourceDictionary.Source;

            if (!(source is null))
            {
                if (ThemeDictionaryCache.TryGetValue(source, out var existingValue))
                {
                    return(existingValue);
                }
            }

            // We are not allowed to use other methods like GetThemeInstance or GetThemeName here as that would cause an endless-loop
            var result = ResourceDictionaryHelper.ContainsKey(resourceDictionary, ThemeInstanceKey) ||
                         string.IsNullOrEmpty(ResourceDictionaryHelper.GetValueFromKey(resourceDictionary, ThemeNameKey) as string) == false;

            if (!(source is null))
            {
                ThemeDictionaryCache[source] = result;
            }

            return(result);
        }
示例#2
0
        public static Theme?GetThemeInstance([NotNull] ResourceDictionary resourceDictionary)
        {
            if (resourceDictionary is null)
            {
                throw new ArgumentNullException(nameof(resourceDictionary));
            }

            if (IsThemeDictionary(resourceDictionary) == false)
            {
                return(null);
            }

            return(ResourceDictionaryHelper.GetValueFromKey(resourceDictionary, ThemeInstanceKey) as Theme);
        }
示例#3
0
        public static string?GetThemeName(ResourceDictionary resourceDictionary)
        {
            if (resourceDictionary is null)
            {
                throw new ArgumentNullException(nameof(resourceDictionary));
            }

            if (IsThemeDictionary(resourceDictionary) == false)
            {
                return(null);
            }

            return(ResourceDictionaryHelper.GetValueFromKey(resourceDictionary, ThemeNameKey) as string);
        }