1.C#中的文件属性可以设置为嵌入的资源,并且不复制到本地

访问嵌入的资源----图片实例-------C#

 

这时候就不能用普通的相对路径来引用了

 

 Assembly assembly = GetType().Assembly;
                                                                   //这时候的路径是:命名空间+文件路径,以点相隔
            System.IO.Stream streamSmall = assembly.GetManifestResourceStream("mytest.leftbutton.png");

            //这个BitmapImage是wpf中的类
            BitmapImage bitmap = new BitmapImage();
            bitmap.BeginInit();//开始初始化
            bitmap.StreamSource = streamSmall;
            bitmap.EndInit();//结束初始化

            this.nininini.Source = bitmap;

 

2.如果是resource文件。就和wpf绑定其他项目里的资源文件xaml的路径一样了

new BitmapImage(new Uri("/MEFA.Controls;component/Resources/Images/leftbutton_紫色.png", UriKind.Relative));

 

相关文章:

  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2021-10-19
猜你喜欢
  • 2022-12-23
  • 2022-02-17
  • 2021-09-17
  • 2022-12-23
  • 2021-04-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案