棱镜嵌入图像

时间:2012-11-08 11:43:08

标签: c# wpf resources prism

我有一个名为xModule模块。我的内部有图片,标记为embedded resource

在我尝试的模块初始化中:

string stFileName = "SmallIcon.png";
string stAssembly = "xModule"; // That's the full name of the assembly
//img.BeginInit();

Uri uri = new Uri(String.Format(@"/{0};component/Images/{1}", stAssembly , stFileName),
                  UriKind.Relative);
ImageSource imgSource = new BitmapImage(uri);

在它到达ImageSource imgSource =..行的断点期间,似乎ImageSource无法找到图像......

为什么呢?怎么了?

我没有错误,引用了程序集。我在Xaml中做了类似的事情并且它起作用了。 也用于:VS11,Unity

1 个答案:

答案 0 :(得分:1)

我认为您需要将图像标记为“资源”而不是“嵌入资源”(WPF)

另见:What's the difference between a Resource and an Embedded Resource in a C# application?