如果我用我的视图中的参数点击执行
GoToNextScreen.Execute(selectedSubMenuIndex);
这会调用我的ViewModel中的方法
private MvxCommand _goSecondCommand;
public IMvxCommand GoSecondCommand
{
get
{
_goSecondCommand = _goSecondCommand ?? new MvxCommand(DoGoSecond);
return _goSecondCommand;
//try to call a command that navigates
}
}
public void DoGoSecond()
{
ShowViewModel<OnlineGroceryShoppingViewModel>(); //action to go to the second view
}
但是当我单步执行时它会直接跳转到DoGoSecond,如何在DoGoSecond方法中访问传递的参数selectedSubMenuIndex?
PS, 我有
var set = this.CreateBindingSet<HomeView, HomeViewModel>();
set.Bind(this).For(v => v.GoToNextScreen).To(vm => vm.GoSecondCommand);
set.Apply();
所以GoToNextScreen调用GoSecondCommand
答案 0 :(得分:2)
您需要使用MvxCommand
的通用版本:
private MvxCommand<int> _goToSecondCommand;
public ICommand GoToSecondCommand =>
_goToSecondCommand = _goToSecondCommand ?? new MvxCommand<int>(DoGoToSecond);
private void DoGoToSecond(int index)
{
// do stuff with index
}
然后,您可以将该索引传递到OnlineGroceryShoppingViewModel
:
ShowViewModel<OnlineGroceryShoppingViewModel>(new { index = index });
然后在OnlineGroceryShoppingViewModel
方法的Init
中获取它:
public void Init(int index)
{
// do stuff based on index
}