Hello,
Please refer to the following code:
XMAL
<Label...>
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding MultiplyBy2Command}"></TapGestureRecognizer>
</Label.GestureRecognizers>
</Label>
Setting BindingContext for testing
public MainPage()
{
InitializeComponent();
this.BindingContext = new CommandDemoViewModel();
}
About the ViewModel , please see Lloyd Sheen's comment. And you also could find this CommandDemoViewModel
in the official doc of Button. (Please define properties of type ICommand in your ViewModel)
For more details, please refer to
Commanding - .NET MAUI | Microsoft Learn
Button - .NET MAUI | Microsoft Learn
Recognize a tap gesture - .NET MAUI | Microsoft Learn
Data binding and MVVM - .NET MAUI | Microsoft Learn
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.