c# - 图像源不会显示图片

标签 c# image windows-phone-8

我在设置 Image Source 属性时遇到问题...所以我尝试使用此代码的每个变体,但由于某种原因它不起作用。 当我手动设置属性时它可以工作,但是当我想在代码中更改图片时它只是空白。

        `BitmapImage` bm = new BitmapImage();
         bm.UriSource=new Uri(this.BaseUri,@"\\Assets\logo6.png");
         this.image.Source = image;

我在按钮事件中使用这段代码,因此我可以在图像控件中更改图片。

最佳答案

您以错误的方式设置了路径。尝试这两个选项中的任何一个都会起作用。

还要确保您的图像属性 Build Action 应设置为 ContentCopy To OutPut Directory to Copy to newerCopy Always

BitmapImage bm = new BitmapImage();
bm.UriSource = new Uri(@"\Assets\Tiles\IconicTileSmall.png",UriKind.Relative);
image.Source = bm;

BitmapImage bm = new BitmapImage();
bm.UriSource = new Uri("\\Assets\\Tiles\\IconicTileSmall.png",UriKind.Relative);
image.Source = bm;

基本上您是在混合使用这两种方式。

关于c# - 图像源不会显示图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25493653/

相关文章:

c# - 无法从解决方案访问 IIS Express 文件夹

c# - asp 的 URL :Image gets messed up

css - 使用带封面的 img 元素

c# - 安装 Json.Net 并在项目中引用它后出错。 window 电话 8

c# - 为什么我不能在 Windows 手机编程中使用 FindResource()?

c# - 将图像添加到列表框

java - 将彩色图像转换为 Array[i][j]

python - 使用 Python 捕获单帧(使用网络摄像头)

c# - Windows 手机 : How to stay in the Current page rather than navigating to another page?

C# StringBuilder AppendFormat 抛出 System.FormatException