我正在为交互式应用程序开发WPF。当我从包含在解决方案中的文件夹中为ImageBrush (Canvas)分配图像路径时,它不能工作,它会转到bin/debug/..在WPF中。但是,当我从目录中分配路径时,它工作得很好。以下是问题的截图:
下面是我编写的不起作用的代码片段:
ImageBrush myBrush = imgContent1;
myBrush.ImageSource = new BitmapImage(new Uri(@"Informatin_Concept_100.jpg", UriKind.Relative));
canContent1Info.Background = myBrush;但是,当我从目录分配图像时,下面的代码片段工作:
C = new System.IO.DirectoryInfo(Environment.CurrentDirectory).Parent.Parent.FullName;
imgContent1.ImageSource = new BitmapImage(new Uri(C + "\\" + "Content1\\Default\\Informatin_Concept_100.jpg", UriKind.Absolute));不知道错误在哪里?
发布于 2017-10-27 05:36:41
使用WPF资源文件包URI从程序集资源加载BitmapImage。Visual项目中图像文件的Build Action必须设置为Resource。
myBrush.ImageSource = new BitmapImage(
new Uri("pack://application:,,,/Informatin_Concept_100.jpg"));https://stackoverflow.com/questions/46966670
复制相似问题