简体   繁体   English

在Windows Phone中更改其来源时图像未出现

[英]Image doesn't appear when changing its source in Windows Phone

When I want to change an image's source, the image simply disappears. 当我想更改图像来源时,图像会消失。

The code I'm using: 我正在使用的代码:

tactImg.Source=tactImgList[i];

tactImgList = new BitmapImage[32];
tactImgList[0] = new BitmapImage(new Uri("ms-appx:///Assets/Images/1.png", UriKind.Absolute));

What am I doing wrong? 我究竟做错了什么? Is there something I need to add to an xaml file or I'm making the global array wrong? 我需要添加到xaml文件中吗,或者我正在使全局数组出错?

You don't need to use ms-appx in Windows Phone 8 projects , it's for WinRT projects. 您不需要在Windows Phone 8项目中使用ms-appx,它用于WinRT项目。

Make sure your image's Build type is Content , remove the ms-appx part and since your image has relative uri , set your UriKind to Relative. 确保图像的Build类型为Content,删除ms-appx部分,并且由于图像具有相对uri,请将UriKind设置为Relative。

First, fill in the data, and then change the source. 首先,填写数据,然后更改源。 tactImgList = new BitmapImage[32]; tactImgList[0] = new BitmapImage(new Uri("ms-appx:///Assets/Images/1.png", UriKind.Absolute)); tactImg.Source=tactImgList[i];

Or use ObservableCollection for storing images. 或使用ObservableCollection来存储图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM