下面的代码适用于 Windows Phone 7
private void ShowTime()
{
txtTime.Text = get24hour();
//display the Date and week.
DateTime nowtime = DateTime.Now;
txtWeek.Text = nowtime.DayOfWeek.ToString();
txtDate.Text = nowtime.Date.ToString("MM/dd");
//create timer to fresh to time
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMinutes(1);
timer.Tick += timer_Ticker;
timer.Start();
}
private void timer_Ticker(object sender, EventArgs e)
{
txtTime.Text = get24hour();
}
private string get24hour()
{
return DateTime.Now.ToString("HH:mm");
}
但 WinRT 中的错误(地铁)
错误部分:
timer.Tick += timer_Ticker;
错误信息:
No overload for 'timer_Ticker' matches delegate 'System.EventHandler<object>'
我该怎么做
我尝试将代码更改为
private void timer_Ticker()
{
txtTime.Text = get24hour();
}
结果
但它再次不起作用,为什么以及如何解决它?:(