You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ResourceDictionary.ContainsKey method never returns trueΒ #13268
ResourceDictionary.ContainsKey method never returns true
Steps to Reproduce
var mergedDictionaries = Application.Current.Resources.MergedDictionaries;
foreach(var dictionary in mergedDictionaries)
{
foreach(var key in dictionary.Keys)
{
bool containsKey = dictionary.ContainsKey(key);
}
}
containsKey is always false. I originally just tried dictionary.ContainsKey("myKey") and it always returned false, which led me to use the above code which should always return true.
@Cybrosys I guess I did something wrong when first trying your extension method. It's working now.
It was a quickly cobbled together method that achieved what I was trying to do when testing something. I wouldn't be surprised if there are some quirks or odd behaviors with it due to how ResourceDictionary behaves.
Activity
tjbarrott commentedon Feb 14, 2023
https://github.com/tjbarrott/MergedDictionariesTest
I put the code in
MainPage.xaml.csThat repo uses .net 6. I also tried it in .net 7 with the same result.
hartez commentedon Feb 14, 2023
This is happening because ResourceDictionary's
ContainsKeymethod only checks the inner dictionary, and ignores the merged dictionaries: https://github.com/dotnet/maui/blob/main/src/Controls/src/Core/ResourceDictionary.cs#L179The method needs to be updated, and the unit tests need to be updated to test for this.
9 remaining items
Ghostbird commentedon Mar 16, 2023
@Cybrosys I guess I did something wrong when first trying your extension method. It's working now.
Cybrosys commentedon Mar 16, 2023
It was a quickly cobbled together method that achieved what I was trying to do when testing something. I wouldn't be surprised if there are some quirks or odd behaviors with it due to how ResourceDictionary behaves.
jfversluis commentedon Apr 6, 2023
Looking at the discussion and linked, closed PR, I think this is a variation of: #11214 (comment)
As such, closing this for now.