MVVMCross:点击通知导航

时间:2018-07-06 13:04:44

标签: c# cross-platform mvvmcross

在该用户通过烤面包通知单击后,我需要导航到某个视图。但这是行不通的。

这是我从AppStart.cs中启动的方法:

protected override async void Startup(object hint = null)
    {
        base.Startup(hint);

        var id = _userManagerService.GetId();
        var token = _userManagerService.GetAccessToken();

        var userIsLogged = !string.IsNullOrWhiteSpace(token) && !string.IsNullOrWhiteSpace(id);

        if (userIsLogged)
        {
            await _navigationService.Navigate<MainViewModel>().ConfigureAwait(false);

            // If the app was not in a memory when notification had been received 
            if (hint is NotificationReceivedEventArgs args)
            {
                // Id of the event which should be opened
                if (Guid.TryParse(args.Parameter, out Guid eventId))
                {
                    // Retrieves the event
                    ViewModels.DataTypes.EventViewModel item = new ViewModels.DataTypes.EventViewModel { Id = eventId };

                    // Navigates to the event page
                    await Task.Run(async () => { await _navigationService.Navigate<EventDetailsViewModel, object, object>(item); }).ConfigureAwait(false);
                }
            };
        }
        else
        {
            await _navigationService.Navigate<LoginViewModel>();
        }
...

首先,我需要检查用户是否已登录到应用程序中,如果是这样,则应用程序将导航到MainViewModel(这是其他视图的容器的主视图:我使用两窗口导航)。

此后,我检查了参数,并且如果检查了NotificationReceivedEventArgs,则需要转到EventDetailsViewModel,但是该视图无法导航:我调查了视图模型生命周期中的“ Prepare”方法和其他方法,但未显示该视图。

但是:

如果我通过以下方式调用导航,则效果很好:

  // Navigates to the event page
  await Task.Run(async () => { await _navigationService.Navigate<EventDetailsViewModel, object, object>(item); }).ConfigureAwait(false);

有人知道为什么会这样吗?

谢谢!

0 个答案:

没有答案