DispatcherTimer.Tick 在 Xamarin Forms 中不受支持

DispatcherTimer.Tick is not supported in Xamarin Forms

我该如何解决这个问题?

建议的替代方案也不起作用。

错误 CS1545 属性、索引器或事件 'DispatcherTimer.Tick' 不受语言支持;尝试直接调用访问器方法 'DispatcherTimer.add_Tick(EventHandler)' 或 'DispatcherTimer.remove_Tick(EventRegistrationToken)'

_timer = new DispatcherTimer();
_timer.Tick += Timer_Tick;
_timer.Interval = new TimeSpan(0, 0, 1);

Windows.UI.Xaml DispatcherTimer is only apply to WinRT, and System.Windows.Threading DispatcherTimer is only apply to .NET Framework. So we can't use both of them into forms. For using timer in Xamarin forms please use Device.StartTimer 替换.

Device.StartTimer (new TimeSpan (0, 0, 60), () =>
{
    // do something every 60 seconds
    Device.BeginInvokeOnMainThread (() => 
    {
      // interact with UI elements
    });
    return true; // runs again, or false to stop
});