Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.Forms MVVM TapGestureRecognizer

I'm writing my first Xamarin.Forms MVVM application and I'm writing the view entirely with XAML. I need to be able to detect when the user taps a Xamarin.Forms.Label and to do so I've followed the example in the following Xamarin guide:

http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/gestures/#Using_ICommand

And my Label's XAML looks like this:

<Label Text="Test Check">
  <Label.GestureRecognizers>
    <TapGestureRecognizer Command="{Binding OnClickCheckOption}"
                          CommandParameter="TestCheck" />
  </Label.GestureRecognizers>
</Label>

This causes a run-time error when the app starts that states:

"An exception of type Xamarin.Forms.Xaml.XamlParseException' occured in Xamarin.Forms.Xaml.DLL but was not handled in user code. Additional information: BindableProperty CommandProperty not found on TapGestureRecognizer"

The error that there is no CommandProperty or CommandParameterProperty on the Xamarin.Forms.TapGestureRecognizer class is clearly not true according to the Xamarin API:

http://iosapi.xamarin.com/?link=T%3aXamarin.Forms.TapGestureRecognizer%2f*

Does anyone know what I'm doing wrong? Any help is greatly appreciated, thanks in advance!

like image 548
user2062604 Avatar asked Jul 25 '14 14:07

user2062604


1 Answers

Your code is valid, and should work, provided you run it on one of the latest build of Xamarin.Forms, as the CommandProperty is brand new.

At the time of this writing, the version you should target is 1.2.2-pre2 (nuget pre-release)

like image 69
Stephane Delcroix Avatar answered Nov 04 '22 23:11

Stephane Delcroix