private static IEnumerable <object> GetMergedDictionariesKeys(ResourceDictionary dictionary) { return(dictionary.GetKeys().Cast <object>().Concat(dictionary.MergedDictionaries.SelectMany(GetMergedDictionariesKeys))); }