Search code examples
xamarinxamarin.iosmvvmcross

MVVMCross iOS static cell command binding


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);
    }
}));

Solution

  • You can bind a Tap straight to a command:

    using MvvmCross.Binding.iOS.Views.Gestures;
    
    set.Bind(this.SomeView.Tap()).For(vm => vm.Command)