我在Windows手機上製作計時器應用程序時遇到問題。 我有文本框設置爲00:00:00,即時嘗試增加它每秒,但在第一秒後,它不會再做。我相信這是一個簡單的解決方案,並會非常感謝任何幫助。謝謝windows phone增加計時器
公衆的MainPage(){ 在InitializeComponent ();
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += OnTimerTick;
timer.Start();
}
void OnTimerTick(object sender, EventArgs args)
{
txtTimer.Text = DateTime.Now.ToString();
}
private void btnStartClick(object sender, EventArgs e)
{
DispatcherTimer timer = new DispatcherTimer();
timer.Tick +=
delegate(object s, EventArgs args)
{
TimeSpan time = new TimeSpan(0);
time += TimeSpan.FromSeconds(1);
this.timenow.Text = string.Format("{0:D2}:{1:D2}:{2:D2}", time.Hours, time.Minutes, time.Seconds);
};
timer.Interval = new TimeSpan(0, 0, 1);
timer.Start();
}
歡迎來到StackOverflow。你有沒有試過調試你的代碼? –