User avatar
stonstad
Topic Author
Posts: 263
Joined: 06 Jun 2016, 18:14
Location: United States
Contact:

Resource Dictionary Item Iteration?

11 Aug 2023, 17:23

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!
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Resource Dictionary Item Iteration?

14 Aug 2023, 16:52

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?
 
User avatar
stonstad
Topic Author
Posts: 263
Joined: 06 Jun 2016, 18:14
Location: United States
Contact:

Re: Resource Dictionary Item Iteration?

15 Aug 2023, 00:11

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.
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Resource Dictionary Item Iteration?

15 Aug 2023, 12:45

I know that I have several hundred. I'm searching from the root, or NoesisView
In which dictionary are the icon resources defined? in a dictionary that is merged into the Application Resources?
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():
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]}");
            }
        }
    }
}
 
User avatar
stonstad
Topic Author
Posts: 263
Joined: 06 Jun 2016, 18:14
Location: United States
Contact:

Re: Resource Dictionary Item Iteration?

15 Aug 2023, 22:32

Awesome! This was really helpful. Thank you!

Image
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Resource Dictionary Item Iteration?

16 Aug 2023, 20:40

Glad to be helpful, marking this as solved.

Who is online

Users browsing this forum: Bing [Bot] and 2 guests