在与主项目不同的库中使用资源图像

时间:2016-01-13 09:48:49

标签: c# wpf image resources .net-assembly

我有一个带有两个库的WPF程序

enter image description here

现在我在主程序和HelperLib中都有灰色资源背景。但另外在HelperLib中我有一个我想要使用的红色背景。

enter image description here

现在,当我想用​​以下内容更改窗口的背景时

 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中的那个,而是使用主程序中的那个,因为我看到资源与程序集相关而不是项目。 两个图像都具有与图片相同的属性:

enter image description here

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

您必须使用带有引用程序集名称的Resource File Pack Uri

  

包://应用:,,, / HelperLib;组件/资源/图像/ gradientWallpaper_RED.jpg

相关问题