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); }
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); }
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); }