Xamarin.iOS MVVMCross忽略尝试关闭窗口根警告的尝试

时间:2019-03-08 05:42:26

标签: mvvmcross

我在Xamarin.iOS项目中使用MVVMCross,其中当我尝试从SecondViewModel导航回FirstViewModel时,我收到警告,提示“忽略尝试关闭窗口根目录(ViewModel类型:SecondViewModel”)在Android上运行良好。

这是我的ViewModels

FirstViewModel.cs

public class FirstViewModel : MvxViewModel
{
   private readonly IMvxNavigationService _navigationService;
   public FirstViewModel(IMvxNavigationService navigationService)
   {
      _navigationService = navigationService;
   }

   private IMvxAsyncCommand _navigateCommand;
   public IMvxAsyncCommand NavigateCommand
   {
      get
      {
          _navigateCommand = _navigateCommand ? ? new MvxAsyncCommand(NavigationMethod);
          return _navigateCommand;
      }
    }


    private async Task NavigationMethod()
    {
       var result = await _navigationService.Navigate<SecondViewModel,
       SecondViewModelArgs, SecondViewReturnArgs>(new SecondViewModelArgs
       {
          TextToSecondViewModel = Text
       });
       Text = result.textToFirstViewModel;
   }
}

SeconViewModel.cs

public class SeconViewModel : MvxViewModel<SecondViewModelArgs, SecondViewReturnArgs>
{

   private readonly IMvxNavigationService _navigationService;+
   public ListExampleViewModel(IMvxNavigationService navigationService)
   {
      _navigationService = navigationService;
   }

   public IMvxCommand NavigateBackCommand => new MvxCommand(NavigateBack);

   private void NavigateBack()
   {
      _navigationService.Close(this, new SecondViewReturnArgs { textToHomeViewModel = Text });
   }
}

FirstViewModel中的NavigateCommand与FirstView上的“打开下一个ViewModel”按钮绑定,而SecondViewModel中的NavigateBackCommand与SecondView上的“关闭视图”按钮绑定。

请告诉我我在这里实施了什么错误

谢谢

0 个答案:

没有答案