MvvmCross : ViewModel Navigation in code

2019-09-11 02:51发布

I got 3 ViewModels. FirstViewModel, SecondViewModel and ThirdViewModel.

I want to click a button in FirstViewModel, then it will open SecondViewModel. After SecondViewModel is opened, without any user interaction, ThirdViewModel will be opened by code.

I couldn't get the ThirdViewModel to open automatically.

        using Cirrious.MvvmCross.ViewModels;

        namespace PortableClassLibrary1.ViewModels
        {
            public class FirstViewModel 
                : MvxViewModel
            {
                private string _hello = "Hello MvvmCross 1";
                public string Hello
                { 
                    get { return _hello; }
                    set { _hello = value; RaisePropertyChanged(() => Hello); }
                }

                private MvxCommand _goSecondCommand;
                public System.Windows.Input.ICommand GoSecondCommand
                {
                    get
                    {
                        _goSecondCommand = _goSecondCommand ?? new Cirrious.MvvmCross.ViewModels.MvxCommand(DoGoSecond);
                        return _goSecondCommand;
                    }
                }

                private void DoGoSecond()
                {
                    ShowViewModel<SecondViewModel>();
                }
            }
        }


        using Cirrious.MvvmCross.ViewModels;

        namespace PortableClassLibrary1.ViewModels
        {
            public class SecondViewModel
                : MvxViewModel
            {
                private string _hello = "Hello MvvmCross 2";
                public string Hello
                {
                    get { return _hello; }
                    set { _hello = value; RaisePropertyChanged(() => Hello); }
                }

                private MvxCommand _goThirdCommand;
                public System.Windows.Input.ICommand GoThirdCommand
                {
                    get
                    {
                        _goThirdCommand = _goThirdCommand ?? new Cirrious.MvvmCross.ViewModels.MvxCommand(DoGoThird);
                        return _goThirdCommand;
                    }
                }

                private void DoGoThird()
                {
                    ShowViewModel<ThirdViewModel>();
                }

                public override void Start()
                {
                    base.Start();

                    DoGoThird();
                }
            }
        }



        using Cirrious.MvvmCross.ViewModels;

        namespace PortableClassLibrary1.ViewModels
        {
            public class ThirdViewModel
                : MvxViewModel
            {
                private string _hello = "Hello MvvmCross 3";
                public string Hello
                {
                    get { return _hello; }
                    set { _hello = value; RaisePropertyChanged(() => Hello); }
                }
            }
        }

0条回答
登录 后发表回答