ICommand.Execute 方法(对象)
ICommand.Execute Method (Object)
如果我用视图中的参数点执行
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
您需要使用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 });
然后在Init
方法中OnlineGroceryShoppingViewModel
获取:
public void Init(int index)
{
// do stuff based on index
}
如果我用视图中的参数点执行
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
您需要使用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 });
然后在Init
方法中OnlineGroceryShoppingViewModel
获取:
public void Init(int index)
{
// do stuff based on index
}