2
votes

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

2 Answers

8
votes

You can bind a Tap straight to a command:

using MvvmCross.Binding.iOS.Views.Gestures;

set.Bind(this.SomeView.Tap()).For(vm => vm.Command)
0
votes

You can use the Tap() like that:

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