C# 为什么分派器委托在WinRT中工作?
下面的代码适用于Windows Phone 7C# 为什么分派器委托在WinRT中工作?,c#,windows-phone-7,windows-8,windows-runtime,microsoft-metro,C#,Windows Phone 7,Windows 8,Windows Runtime,Microsoft Metro,下面的代码适用于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 = n
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(Metro)中出现错误
错误部分:
timer.Tick += timer_Ticker;
错误消息:
No overload for 'timer_Ticker' matches delegate 'System.EventHandler<object>'
结果但它又不起作用了,为什么以及如何解决它(我阅读了msdn,并将委托方法更改为下面的方法,它可以工作:
private void timer_Ticker(object sender, object e)
{
txtTime.Text = get24hour();
}
timer.Tick+=新的事件处理程序(timer\u Tick);
私有无效计时器(对象发送方,对象e)
{
}
指
private void timer_Ticker(object sender, object e)
{
txtTime.Text = get24hour();
}
timer.Tick += new EventHandler<object>(timer_Tick);
private void timer_Tick(object sender, object e)
{
}