0

I have a a Solution folder Icons in which I store some png files. These files have build action set to Resource so I can bind to it from the view.

I want to create a combobox listing all available png files letting the user choose one. I planned to do so by populating a list of the binding path to each of the available png files. Manually creating that list would be easy and would work, but I would prefer to reflect and automatically let my class populate the list. How can I do that?

I found this code, but it only works if the build action for the PNG files are set to Embedded Resource, but then the bindings I already have in some views fails.

string[] resources = System.Reflection.Assembly.GetCallingAssembly().GetManifestResourceNames();

Please observe, I do not want to copy all these png files to the build output directory it is not an acceptable solution in this case.

Johan
  • 502
  • 4
  • 18

1 Answers1

1

Give this a try: Files marked with build action of “Resource” are added to a special resx file called ProjectName.g.resx. This file is generated during the build, it is not part of the project.

var resourceManager = new ResourceManager("ProjectName.g", Assembly.GetExecutingAssembly());
var resources = resourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
foreach (var res in resources)
{
    /// Do what you need
}
Clemens
  • 123,504
  • 12
  • 155
  • 268
andyb952
  • 1,931
  • 11
  • 25