MAUI .NET 8 iOS - Span TapGestureRecognizer not working

Aneetha 65 Reputation points
2024-07-19T05:10:43.3166667+00:00

I have created a new MAUI .NET 8 project and migrated the Xamarin forms project code.

In iOS, the span text TapGestureRecognizer is not working.

gesture_Tapped event is not triggered.

var sp2 = new Span { Text = "Click here" };

TapGestureRecognizer gesture = new TapGestureRecognizer
{
    NumberOfTapsRequired = 1
};

sp2.GestureRecognizers.Add(gesture);



gesture.Tapped += gesture_Tapped;


private void gesture_Tapped(object? sender, EventArgs e)
{
    EmailTest email = new EmailTest();
    email.SendEmail(StringConstants.TEXT_EMAIL);
}

How do I resolve this issue?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,607 questions
{count} votes

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 32,546 Reputation points Microsoft Vendor
    2024-07-19T08:10:34.6666667+00:00

    Hello,

    There is a known issue that has been fixed in .NET8.0.40 - TapGestureRecognizer does not work in label's span · Issue #8004 · dotnet/maui (github.com))

    I try to new a label and add the span, the event can be triggered with latest VS and 8.0.70.

    Please manage NuGetPackages, then update Microsoft.Maui.Controls and Microsoft.Maui.Controls.Compatibility.

    FormattedString formattedString = new FormattedString();
    formattedString.Spans.Add(sp2);
    MyLabel.FormattedText = formattedString;
    

    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.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.