【问题标题】:How to stop the timer in windows 8?如何在 Windows 8 中停止计时器?
【发布时间】:2013-08-03 14:04:50
【问题描述】:

我的应用程序中的计时器正在做一些更改,我希望它在执行 stop() 方法时停止,当更改对我来说足够时它不会停止。

timerpartAnimation = new DispatcherTimer();
timerpartAnimation.Interval = TimeSpan.FromMilliseconds(1);
timerpartAnimation.Tick += timer_Tick_Anime;
timerpartAnimation.Start();

public void timer_Tick_Anime(object sender, object e)
    {
        newL-=3;
        newT = A * newL + B;
        playPart33.Margin = new Thickness(newL, newT, playPart33.Margin.Right, playPart33.Margin.Bottom);
        if (dis(playPart33.Margin, currentIm.Margin))
        {
            timerpartAnimation.Stop();
            currentIm.Visibility = Windows.UI.Xaml.Visibility.Visible;
        }
    }

奇怪的是这一行:

currentIm.Visibility = Windows.UI.Xaml.Visibility.Visible;

确实发生了,所以它肯定会进入 if 范围。

有人有想法吗?

【问题讨论】:

标签: c# windows xaml windows-8 windows-store-apps


【解决方案1】:

你可以写一个滴答作响的函数。

   public static void ticking(bool tick)
   {
    if(tick)
    {
    timerpartAnimation.Interval = TimeSpan.FromMilliseconds(1);
    }
    else
    {
    timerpartAnimation.Interval = TimeSpan.FromMilliseconds(0);
    }
   }

所以ticking(false); 表示停止计时器。

【讨论】:

    猜你喜欢
    • 2012-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-05
    相关资源
    最近更新 更多