maui
maui copied to clipboard
Fixed ResourceDictionary.ContainsKey method
Description of Change
This change fixes the resource dictionary ContainsKey method so that it also searches for key in merged dictionaries. Currently the ContainsKey method only looks at the inner dictionary of the primary resource dictionary and disregards merged dictionaries.
Issues Fixed
Fixes #13268
Thank you for your pull request. We are auto-formating your source code to follow our code guidelines.
@kunyli I asked @StephaneDelcroix about this and it turns out that this behavior (where ContainsKey ignores the merged dictionaries) might be important for Hot Reload. So we should hold off merging this until we can figure it all out.
Hello @hartez ,
Following up on the above comment that Hot Reload might be dependent on ContainsKey current behavior, is that not an undesired dependency?
Currently ContainsKey return false while Keys.Contains returns true, that is not correct regardless of external dependencies.
If you create a new project, that project will contain two resource dictionaries (Colors.xaml and Styles.xaml). Those are put into the app's main resource dictionary as merged dictionaries. Looking at both those two dictionaries, all of the values are inside the _mergedInstance , none of the values are in _innerDictionary. Using ContainsKey on any of the resource dictionary instances will always return false.
My understanding is that _mergedInstance represents the styling and values loaded from Xaml resource files while the _innerDictionary acts as an override to those values, as it is checked to contain values before any other ResourceDictionary instance.
So the dependency for Hot Reload would then be that it relies on ContainsKey to indicate if a value has been overridden or not?
Hello @hartez ,
Following up on the above comment that Hot Reload might be dependent on
ContainsKeycurrent behavior, is that not an undesired dependency?
From our perspective, it's highly undesired. But it's not something we can change at the moment, since those dependencies are external. It would have to be coordinated with a future version of VS.
So the dependency for Hot Reload would then be that it relies on
ContainsKeyto indicate if a value has been overridden or not?
I believe you're correct. As I understand it, there are also some other quirks of RD that HR relies on. Hopefully it's something we can address in a future version to make the API less confusing.
Closing this since we're not going to make this change right now.