How can I (Why I can't) get the keys or values in App.Current.Resources? #8166
-
These works: var color = App.Current.Resources["SystemAccentColor"]; // #FF0078D4
bool containsKey = App.Current.Resources.ContainsKey("SystemAccentColor"); // true
App.Current.Resources.TryGetValue("SystemAccentColor", out var value); // #FF0078D4
bool keyContains = App.Current.Resources.Keys.Contains("SystemAccentColor"); // true But these doesn't work: var keys = App.Current.Resources.Keys.ToList(); // empty
var values = App.Current.Resources.Values.ToList(); // empty By the way, this returns 639 items but doesn't contain "SystemAccentColor", so I assume the collection is not complete. // Returns false
bool mergedContains = App.Current.Resources.MergedDictionaries
.SelectMany(x => x.Keys)
.ToList()
.Contains("SystemAccentColor"); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I was looking around at the documentation and I did find a paragraph on system resources. But to put it simply, system resources are not in the Xaml resource dictionary. |
Beta Was this translation helpful? Give feedback.
-
Yep. It seems to be that there are some special cases implemented. I just run into this behavior when I was asked if one can create a list of those resources. Thanks @DarranRowe! |
Beta Was this translation helpful? Give feedback.
Yep. It seems to be that there are some special cases implemented. I just run into this behavior when I was asked if one can create a list of those resources. Thanks @DarranRowe!