Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
992 views
in Technique[技术] by (71.8m points)

MvvmCross : ViewModel Navigation in code

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); }
                }
            }
        }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...