可能有一个更优雅的解决方案,但这样的事情会为您提供 Main.Data 中所有 jpg 的资源字符串或 URI:
private void LoadImages ()
{
var asm = Assembly.LoadFrom("Main.Data.dll");
var rm = new System.Resources.ResourceManager(asm.GetName().Name + ".g", asm);
var resourceSet = rm.GetResourceSet(Thread.CurrentThread.CurrentCulture, true, true);
var resourceUris = new List<Uri>();
var resourceStrings = new List<String>();
foreach (var resource in
resourceSet.Cast<DictionaryEntry>().Where(resource => ((string) resource.Key).EndsWith("jpg")))
{
resourceStrings.Add((string)resource.Key);
resourceUris.Add(
new Uri(String.Format("pack://application:,,,/Main.Data;component/{0}",
((string) resource.Key))));
}
rm.ReleaseAllResources();
// Do something with resourceStrings or resourceUris...
}