Mvvmcross 6.2.3 странное поведение навигации viewmodel - PullRequest
0 голосов
/ 26 марта 2019

Я играю с MVVMCROSS 6.2.3, и у меня есть проблема с вложенной навигацией в моем приложении XForms UWP.

Вот описание: VM1 перейдет к VM2 и VM1 ожидает результата VM2 !

VM2 перейти к VM3, VM2 не требует результата VM3. После перехода от ВМ2 к ВМ3 и ВМ1 неожиданно получается нулевой результат.

public class MainViewModel : MvxViewModel
{
    public IMvxAsyncCommand GoToSecondPageCommand =>
        new MvxAsyncCommand(async () =>
        {
            var param = new Dictionary<string, string> { { "ButtonText", ButtonText } };

            var result = await navigationService.Navigate<SecondViewModel, Dictionary<string, string>, SecondViewModelResult>(param);
            var breakpoint = 1;


            //HERE IS THE ISSUE, result IS NULL because it fires immediately after Navigate<ThirdViewModel>()


        });

    public IMvxAsyncCommand BackCommand => new MvxAsyncCommand(async () =>
    {
        await navigationService.Close(this, new SecondViewModelResult { Result = "Back button clicked" });
    });
}

public class SecondViewModel : MvxViewModel<Dictionary<string, string>, SecondViewModelResult>
{
    public IMvxAsyncCommand GoToThirdPageCommand =>
        new MvxAsyncCommand(async () =>
        {
            var t = await navigationService.Navigate<ThirdViewModel>();
            var breakpoint = 2;
        });
}

public class ThirdViewModel : MvxViewModel
{
}

Вы можете запустить его самостоятельно с моего GitHub https://github.com/JTOne123/XamFormsMvxTemplate

Такое поведение было хорошим в версии 5.7, и VM1 ожидает, пока VM2 вернет результат .

Что я делаю не так?

1 Ответ

0 голосов
/ 09 апреля 2019

Перед вызовом await navigationService.Navigate<ThirdViewModel>(); в GoToThirdPageCommand вы можете закрыть текущий SecondViewModel, позвонив, например: await navigationService.Close(this, new SecondViewModelResult { Result = "Third page command clicked" });

В результате будет возвращен второй параметр.

Итак, вы получите что-то вроде этого:

public IMvxAsyncCommand GoToThirdPageCommand =>
    new MvxAsyncCommand(async () =>
    {
        await navigationService.Close(this, new SecondViewModelResult { Result = "Third page command clicked" });
        await navigationService.Navigate<ThirdViewModel>();
    });
...