0

下面的代码适用于 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();
    }

结果
但它再次不起作用,为什么以及如何解决它?:(

4

2 回答 2

2
timer.Tick += new EventHandler<object>(timer_Tick); 

private void timer_Tick(object sender, object e)
{
}

参考这个链接

于 2012-06-20T08:02:14.707 回答
0

我阅读了 msdn 并将委托方法更改为下面并且它可以工作:

    private void timer_Ticker(object sender, object e)
    {
        txtTime.Text = get24hour();
    }
于 2012-06-17T15:31:23.670 回答