C# WPF -MaterialDesignTheme 找不到资源“xxx“问题记录

WPF工程框架:.Net Framework4.0。

MaterialDesignTheme版本:最新稳定版5.3.0

工程内有方法如下:

复制代码
  public static BitmapImage GetBitImage(string path)
  {
      try
      {
          BitmapImage bitmap = new BitmapImage();
          bitmap.BeginInit();
          bitmap.UriSource = new Uri(path);
          bitmap.CacheOption = BitmapCacheOption.OnLoad;
          bitmap.EndInit();
          bitmap.Freeze(); 
          return bitmap;
      }
      catch (Exception e)
      {
          System.Windows.MessageBox.Show("GetBitImage error,message:"+e.Message);
          return null;
      }
  }

调用如下:

复制代码
public BitmapImage pic= GetBitImage("pack://application:,,," + "/Resource/Images/pic.png");

方法是将工程资源文件转为BitmapImage对象并返回,在安装MaterialDesignTheme再卸载前一切正常。

当执行上述操作后,关闭应用程序会弹窗报错:找不到资源"resource/images/pic.png",原因不明

解决方案:

将工程的所属的.vs目录,bin目录,obj目录,packages目录,Propertyies目录,App.xaml文件,App.xaml.cs文件,.csproj文件,.sln文件.packages.config文件替换回此前备份解决。

如有大佬直到真实原因,请斧正,谢谢!

相关推荐
helloworldandy1 天前
高性能图像处理库
开发语言·c++·算法
2401_836563181 天前
C++中的枚举类高级用法
开发语言·c++·算法
chao1898441 天前
矢量拟合算法在网络参数有理式拟合中的应用
开发语言·算法
EmbedLinX1 天前
C++ 面向对象
开发语言·c++
weixin_445402301 天前
C++中的命令模式变体
开发语言·c++·算法
Hgfdsaqwr1 天前
实时控制系统优化
开发语言·c++·算法
2301_821369611 天前
嵌入式实时C++编程
开发语言·c++·算法
sjjhd6521 天前
多核并行计算优化
开发语言·c++·算法
一起养小猫1 天前
Flutter for OpenHarmony 实战 表单处理与验证完整指南
android·开发语言·前端·javascript·flutter·harmonyos
leiming61 天前
FreeRTOS 的任务与 Linux
java·开发语言