2

I'm developing an app with MVVMCross wich uses storyboard for the UI. In the storyboard I have a UITableView with static cells in it. How can I bind an ICommand (or IMvxCommand) to a click or touch on the static cell?

At the moment I'm using a UITapGestureRecognizer but in my opinion it's not the most suitable way.

tableViewController.StaticCell.AddGestureRecognizer(new UITapGestureRecognizer(() =>
{
    if (ViewModel.SomeCommand.CanExecute())
    {
        ViewModel.SomeCommand.Execute(null);
    }
}));

2 Answers 2

8

You can bind a Tap straight to a command:

using MvvmCross.Binding.iOS.Views.Gestures;

set.Bind(this.SomeView.Tap()).For(vm => vm.Command)
2
  • 2
    Thx! You pointed me in the right direction! There where some minor errors in your code. This worked for me: set.Bind(view.SomeView).For("Tap").To(vm => vm.Command) May 19, 2016 at 11:53
  • The .Tap()is only available with the correct using.
    – Martijn00
    Mar 31, 2017 at 11:33
0

You can use the Tap() like that:

set.Bind(myView.Tap()).For(v=>v.Command).To(vm => vm.myViewModelCommand);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.