Resource Dictionary Item Iteration?
My game has several hundred XAML icons and I'm hoping to create a user interface that shows them all in one place as a 'style guide'. I am trying to iterate through my resource dictionaries, but everything is showing zero keys.
i.e.
FrameworkElement.Resources // empty
or
foreach (ResourceDictionary dictionary in resources.MergedDictionaries) // empty
What is the best way to accomplish this?
Thank you!
i.e.
FrameworkElement.Resources // empty
or
foreach (ResourceDictionary dictionary in resources.MergedDictionaries) // empty
What is the best way to accomplish this?
Thank you!
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Resource Dictionary Item Iteration?
Hi, ResourceDictionary implements the IDictionary interface, so you can get access to the Keys collection, and then iterate that to obtain the corresponding values. But first you need to get access to the correct dictionary that defines all those icons. Is that dictionary part of the application resources? Is it merged there?
Re: Resource Dictionary Item Iteration?
Hi Sergio. All of the dictionaries that I am looking at via the inspector show zero keys. I know that I have several hundred. I'm searching from the root, or NoesisView.
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Resource Dictionary Item Iteration?
In which dictionary are the icon resources defined? in a dictionary that is merged into the Application Resources?I know that I have several hundred. I'm searching from the root, or NoesisView
If the dictionary with the icons is part of the Application Resources you won't find it merged in any element of the View. You can get it by calling Noesis.GUI.GetApplicationResources():
Code: Select all
public class DictEnumBehavior : MonoBehaviour
{
void Start()
{
ResourceDictionary appResources = Noesis.GUI.GetApplicationResources();
Debug.Log("App.Resources >");
foreach (var key in appResources.Keys)
{
Debug.Log($" '{key}' = {appResources[key]}");
}
Debug.Log("App.Resources.Merged >");
foreach (var dict in appResources.MergedDictionaries)
{
Debug.Log($"+ {dict.Source}:");
foreach (var key in dict.Keys)
{
Debug.Log($" '{key}' = {dict[key]}");
}
}
}
}Re: Resource Dictionary Item Iteration?
Awesome! This was really helpful. Thank you!


-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Resource Dictionary Item Iteration?
Glad to be helpful, marking this as solved.
Who is online
Users browsing this forum: Bing [Bot] and 2 guests