只需创建一个计时器,当它达到 5000 毫秒时切换图像和。
设置变量...
// Timer Stuff
static Boolean stopped = true;
static long dd = 0, hh = 0, mm = 0, ss = 0, ms = 0, gtdd = 0, gthh = 0, gtmm = 0, gtss = 0;
static Stopwatch stopwatch = new Stopwatch();
Timer timer;
bool ShowImage1 = true;
准备好后启动计时器。注意我们接下来要添加的 updateDisplay 函数。
stopwatch.Start();
timer = new Timer(new TimerCallback(updateDisplay), AdventureTimer, 0, 100);
创建你的 updateDisplay 函数。在这里,您将检查以查看要显示的图像。
public void updateDisplay(Object displayBlock)
{
if (stopwatch.ElapsedMilliseconds >= 5000) {
Dispatcher.BeginInvoke(new Action(ToggleImage);
}
}
创建一个函数来切换图像。
public void ToggleImage()
{
stopwatch.Reset();
if (ShowImage1 == true)
{
ImageGrid.Visibility = Visibility.Visible;
ParisLive.Visibility = Visibility.Collapsed;
ShowImage1 = false;
}
else
{
ImageGrid.Visibility = Visibility.Collapsed;
ParisLive.Visibility = Visibility.Visible;
ShowImage1 = true;
}
}