Xamarin.Forms

Xamarin Gesture

Gesture Event

When we put the control of Label, the Label does not provide any event. <Label x:Name=“lblSignUp Text=“Dont’t have account?”/> as shown the Label only display purpose only.

When the user want to replace Button with Label, then we give the event for Label. As shown below:

XAML

<Label x:Name="lblSignUp" Text="Don't have an account?" Grid.Row="8" Grid.Column="1" Grid.ColumnSpan="2">
  <Label.GestureRecognizers>
    <TapGestureRecognizer
   Tapped="lblSignUp_Tapped"/>
  </Label.GestureRecognizers>

C#

var lblSignUp_Tapped = new TapGestureRecognizer();   
lblSignUp_Tapped.Tapped += (s,e) =>
{
//
//  Do your work here.
//
};
lblSignUp.GestureRecognizers.Add(lblSignUp_Tapped);

The Screen Below shown the Label Event. Screen 1 : The Label “Don’t have an account?” as shown in Bottom . The Label "Don't have an account?" as shown in Bottom .

When the User click the Label “Don’t have an account?”, it will Navigate to Sign Up Screen. enter image description here For more details: https://developer.xamarin.com/guides/xamarin-forms/user-interface/gestures/tap/


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow