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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…