1

我正在开发一个WP8应用程序,并想image用几张图片更改背景;将时间设置为变量并在 C# 中显示图像,

4

1 回答 1

0

您可以使用DispatcherTimer 类来根据时间更改图像。

让我建议你最简单的方法。将您的图像命名为 1.jpg、2.jpg、3.jpg 等数字,并将它们放在一个文件夹中。

现在您可以使用随机数类以随机顺序选择图像,也可以使用以下方法获取顺序:

DispatcherTimer picture_timer = new DispatcherTimer();
Random rnd = new Random();

picture_timer .Interval = new TimeSpan(0, 0, 3);
                   picture_timer .Tick += timer_Tick;
                   picture_timer .Start();

 void timer_Tick(object sender, object e)
        {
int num = rnd.Next(1, 13); // creates a number between 1 and 12
string image_source = "/Assets/"+num+".jpg";

}
于 2016-04-27T11:32:09.447 回答