【问题标题】:Image doesn't appear when changing its source in Windows Phone在 Windows Phone 中更改其来源时不显示图像
【发布时间】:2015-08-16 20:40:50
【问题描述】:
当我想更改图像的来源时,图像就会消失。
我正在使用的代码:
tactImg.Source=tactImgList[i];
tactImgList = new BitmapImage[32];
tactImgList[0] = new BitmapImage(new Uri("ms-appx:///Assets/Images/1.png", UriKind.Absolute));
我做错了什么?有什么我需要添加到 xaml 文件中的,还是我弄错了全局数组?
【问题讨论】:
标签:
c#
.net
windows
windows-phone-8
【解决方案1】:
你不需要在 Windows Phone 8 项目中使用 ms-appx,它是用于 WinRT 项目的。
确保您的图像的构建类型是 Content ,删除 ms-appx 部分,并且由于您的图像具有相对 uri ,请将您的 UriKind 设置为 Relative。
【解决方案2】:
首先填写数据,然后更改来源。
tactImgList = new BitmapImage[32];
tactImgList[0] = new BitmapImage(new Uri("ms-appx:///Assets/Images/1.png", UriKind.Absolute));
tactImg.Source=tactImgList[i];
或者使用ObservableCollection来存储图片。