【发布时间】:2011-09-09 07:38:45
【问题描述】:
在过去的 2 天里,这一直让我发疯,我发现任何接近的东西似乎都不适用于我的情况,也许有人可以指出我做错了什么。
我有一个 WPF 项目,其中包含相当多的图像(80ish)。我已将它们添加到项目中的一个名为“Images”的文件夹中。它们目前被设置为嵌入式资源(尽管我也尝试过常规资源)但似乎没有任何效果。
我正在尝试使用这些文件作为源来创建和加载 Image 类型的 ArrayList,但我失败了。
private void addPicture(string name)
{
string filePath = "pack://MyApp_WPF:,,,/Images/" + name + ".png";
Stream imageStream = assembly.GetManifestResourceStream(filePath);
Image curImage = new Image();
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
bmpImage.UriSource = new Uri(filePath, UriKind.Relative);
bmpImage.EndInit();
curImage.Height = 60;
curImage.Stretch = Stretch.Uniform;
curImage.Source = bmpImage;
curImage.Margin = new Thickness(5);
imageList.Add(curImage);
}
在我的 Windows 窗体应用程序中执行此操作要容易得多,但我无法用 WPF 解决...除了资源链接之外的任何帮助都会很好,因为此时我已经阅读了它们。
【问题讨论】:
标签: c# wpf embedded-resource