2017-07-13 1 views
0

Si je les points sur Exécuter avec un paramètre de mon point de vueICommand.Execute méthode (Object)

GoToNextScreen.Execute(selectedSubMenuIndex);

et cela appelle une méthode dans mon 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 
     } 

mais il saute directement à DoGoSecond quand je passe à travers, comment puis-je accéder au paramètre passé, selectedSubMenuIndex, dans la méthode DoGoSecond?

PS, j'ai

var set = this.CreateBindingSet<HomeView, HomeViewModel>(); 
set.Bind(this).For(v => v.GoToNextScreen).To(vm => vm.GoSecondCommand); 
set.Apply(); 

appelle si GoToNextScreen GoSecondCommand

Répondre

2

Vous devez utiliser la version générique de MvxCommand:

private MvxCommand<int> _goToSecondCommand; 
public ICommand GoToSecondCommand => 
    _goToSecondCommand = _goToSecondCommand ?? new MvxCommand<int>(DoGoToSecond); 

private void DoGoToSecond(int index) 
{ 
    // do stuff with index 
} 

Vous pouvez ensuite passer cet index le long de votre OnlineGroceryShoppingViewModel:

ShowViewModel<OnlineGroceryShoppingViewModel>(new { index = index }); 

obtenir ensuite dans OnlineGroceryShoppingViewModel dans la méthode Init:

public void Init(int index) 
{ 
    // do stuff based on index 
} 
+0

u r mon héros! J'ai vu vos commentaires sur les forums Xamarin, comment puis-je devenir aussi sage que vous? Merci encore! –

+1

Cire, décoller – Cheesebaron