0

我的项目有两个页面,当我从 page1 导航到 page2 时,我使用下面的代码在堆栈面板上加载图片

var imageResource = Application.GetResourceStream(
          new Uri("WindowsPhonePuzzle;component/numbers/numbergame.png",
          UriKind.Relative));   
 this.ImageStream = imageResource.Stream;

如果我想要两张或更多张图片并每次随机加载或连续加载我必须更改什么?

4

1 回答 1

1

您需要将要使用的图像的 Uris 存储在某种集合中。然后使用随机选择一个。

Random r = new Random(DateTime.Now.Millisecond);
int index = r.Next(0, myCollection.Count);
var imageResource = Application.GetResourceStream(new Uri(myCollection[i], UriKind.Relative)); 
this.ImageStream = imageResource.Stream;

您也可以直接访问资源,但您需要确保您正在处理图像的 Uri。

于 2012-10-27T15:51:40.740 回答