MvvmCross : ViewModel Navigation in code

青春壹個敷衍的年華 提交于 2019-12-25 04:22:49

问题


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); }
                }
            }
        }

来源:https://stackoverflow.com/questions/25020587/mvvmcross-viewmodel-navigation-in-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!