在与主项目不同的库中使用资源映像 [英] Using a resource image in a library different from the main project
问题描述
我有一个带有两个库的WPF程序
I have a WPF program with two libraries
现在内部,我在主程序和HelperLib中都具有灰色资源背景。但是另外,在HelperLib中,我想使用红色背景。
now inside I have a gray resource background both in the main program and HelperLib. But additionally in the HelperLib I have a red background I want to use.
现在,当我想使用以下方式更改窗口的背景时:
Now when I want to change the background of a window with:
switch (bubbleType)
{
case eBubbleType.ERROR:
bw.btText.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/gradientWallpaper_RED.jpg"))); <-----I want to use this one
break;
default:
bw.btText.Background = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/Resources/Images/gradientWallpaper.jpg")));
break;
}
但我在RED图像上却找不到图像,但在另一个。
我怀疑使用灰度渐变时,它不是在lib中使用而是在主程序中使用,因为我看到资源与程序集无关,而与项目无关。
这两个图像都具有与图片相同的属性:
but I get an image not found exception on the RED image but not on the other one. I suspect that, when using the gray gradient it's not using the one in the lib but the one in the main program since I see that the resource is related to the assembly not to the project. Both images have the same properties as in picture:
感谢您的帮助
推荐答案
您必须使用资源文件包Uri ,其中包含所引用程序集的名称:
You would have to use a Resource File Pack Uri with the name of the referenced assembly:
new Uri(
"pack://application:,,,/HelperLib;component/Resources/Images/gradientWallpaper_RED.jpg")
这篇关于在与主项目不同的库中使用资源映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!