How to create click event on label in xamarin forms dynamically

For people who prefer to use XAML and who like to bind Command directly to the ViewModel, you can use this:

<Label HorizontalOptions="Center"
       TextColor="Blue"
       FontSize="20"
       Text="Forgot Password?">
    <Label.GestureRecognizers>
        <TapGestureRecognizer Command="{Binding ForgotPasswordCommand}" />
    </Label.GestureRecognizers>
</Label>

And then in your ViewModel, you’ll just assign the command to your function:

public ICommand ForgotPasswordCommand => new Command(OnForgotPassword);

And then define the function with all the work get done:

private async void OnForgotPassword()
{ ... }

PS: You will need to declare that you are using System.Windows.Input;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)