Is it possible to add gestures to images in .NET MAUI?

Platform: .NET MAUI| Category: General

Yes, you can add gestures to images by wrapping them in a GestureRecognizers collection. For example, you can add a TapGestureRecognizer to handle tap events on the image, as demonstrated in the following code:

var image = new Image
{
    Source = "art.png",
    WidthRequest = 200,
    HeightRequest = 200,
};
var tapGesture = new TapGestureRecognizer();
tapGesture.Tapped += (sender, e) =>
{
    DisplayAlert("Image Tapped", "You tapped the image!", "OK");
};

image.GestureRecognizers.Add(tapGesture);

Content = new StackLayout
{
    Children = { image },
    VerticalOptions = LayoutOptions.Center, 
    HorizontalOptions = LayoutOptions.Center,
};

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.