MAUI Tap Gesture on Hyperlink not working

170 Views Asked by At

Implemnted code below "Create a reusable hyperlink class" at MS Learn MAUI:Entry to add a Hyperlink. The Tap Gesture is added but does not fire the Tap handler. There is some discussion of this at GitHub dotnet/maui TapGestureRecognizer ... . My workaround is to add a Button to action the jump to a browser.

1

There are 1 best solutions below

0
Jianwei Sun - MSFT On

What you mean is that you want to add a TapGesture on the Entry and jump to the browser with specific Hyperlink when the entry is clicked?

If so, you can achieve it by the following code:

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiApp3.MainPage">
    <StackLayout>
        <Entry>
            <Entry.GestureRecognizers>
                <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
            </Entry.GestureRecognizers>
        </Entry>
    </StackLayout>
</ContentPage>
public partial class MainPage : ContentPage
{

   public MainPage()
    {
        InitializeComponent();
    }


   private async void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
    {
        Uri uri = new Uri("https://www.bing.com");
        await Browser.Default.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);
    }
}

Update

For Android/iOS, it works well. But when I test it on Windows, it doesn't fire the Tap handler. I also find an issue on GitHub: [Windows] TapGestureRecognizer not working on Entry. You can follow up it to see if any update.