WPF:在.resx文件中创建列表或项目数组

我能够使用此链接中的代码查看.resx文件中的项目列表

using System.Collections; using System.Globalization; using System.Resources; ... string resKey; ResourceSet resourceSet = MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true); foreach (DictionaryEntry entry in resourceSet) { resKey = entry.Key.ToString(); ListBox.Items.Add(resKey); } 

我现在想做的是创建一个可访问的列表或数组。 我该怎么做呢? 为了澄清,我不想创建一个Image容器数组,并使用循环来加载.resx文件中的图像。 谢谢

我不确定我是否正确,但可能这就是你想要的:

 var resources = new List(); foreach (DictionaryEntry entry in resourceSet) { resources.Add(entry.Key.ToString()); } 

UPDATE

好的,那么这是另一个解决方案。 您可以遍历resourceSet的值,如果任何值是Bitmap ,则将其转换为BitmapImage并添加到列表中。 像这样:

 var images = resourceSet.Cast() .Where(x => x.Value is Bitmap) .Select(x => Convert(x.Value as Bitmap)) .ToList(); public BitmapImage Convert(Bitmap value) { var ms = new MemoryStream(); value.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); var image = new BitmapImage(); image.BeginInit(); ms.Seek(0, SeekOrigin.Begin); image.StreamSource = ms; image.EndInit(); return image; }