Enumerate image resources in dotnet MAUI

Viewed 55

I have a folder structure in my MAUI project

/Resources
  /Images
    dotnet_bot.svg
    
    /LocationTypeIcons
      _default.svg
      bar.svg
      restaurant.svg
      grocery.svc
      ...

and then in my csproj I have

<MauiImage Include="Resources\Images\*" />
<MauiImage Include="Resources\Images\LocationTypeIcons\*" />

I'm trying to find a way to, in code, iterate over the icons that I have in the LocatationTypeIcons folder to conditionally use one if the name of a field matches it, but use _default if it doesn't.

I'm looking to do something like

Directory.EnumerateFiles( "???/LocationTypeIcons" )

Or maybe something along the lines of

App.Current.Resources.GetResourcesByTypeAndPath("Images", "LocationTypeIcons");

really anything that works, I know that I can build the following map, but I was trying to avoid having to put the data in a bunch of places and wanted to let the presence of the svgs and their filenames dictate which icons were available.

   public static Dictionary<string, string> TypeMap = new {
     { "bar", "bar.png" },
     { "restaurant", "restaurant.png" },
     { "grocery", "grocery.png" }
   };

If I have to do something platform specific for each platform, that's fine too (though obv not preferred) but even in platform specific code, I'm not sure how to access this information.

0 Answers
Related