我在 Windows 手机上制作计时器应用程序时遇到问题。我将文本框设置为 00:00:00 并且我试图每秒增加一次,但在第一秒之后它不会再做任何事情了。我相信这是一个简单的解决方法,并且非常感谢任何帮助。谢谢
公共 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();
}