WPF:在.resx文件创建项目列表或数组 [英] WPF: Creating a List or array of items in a .resx file
问题描述
我能够使用此链接以在.resx文件查看的项目列表
I was able to use code in this link to view a list of items in a .resx file
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);
}
我想现在要做的,就是创建一个accessable列表或数组。我怎么会去这样做?
要澄清,我wan't创建图像的容器的阵列,并用一个循环加载图像.resx文件。
谢谢
What I want to do now, is create an accessable list or array. How do I go about doing this? To clarify, I wan't to create an array of Image containers, and use a loop to load the images in the .resx file. Thanks
推荐答案
我真的不知道,我得到你的权利,但可能这是你想要什么:
I`m not sure that I get you right but probably this is what you want:
var resources = new List<string>();
foreach (DictionaryEntry entry in resourceSet)
{
resources.Add(entry.Key.ToString());
}
更新
好吧,那么这里是另一种解决方案。您可以通过您的ResourceSet值迭代,如果任何值为位图
- 将其转换成的BitmapImage,并添加到列表中。像这样的:
Ok, then here is another solution. You can iterate through values of your resourceSet and if any value is a Bitmap
- convert it into BitmapImage and add to your list. Like this:
var images = resourceSet.Cast<DictionaryEntry>()
.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;
}
这篇关于WPF:在.resx文件创建项目列表或数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!