Xamarin TapGestureRecognizer 有时无法正常工作

Xamarin TapGestureRecognizer sometime does not work properly

我目前正在使用 Xamarin.Forms 构建我的移动应用程序,当我尝试使用 Xamarin.Forms gestures more particularly a tap gesture 时遇到了问题(在 ios 和 android 两个平台上)在 xaml 标签 上。因为我想将此标签用作 link.

问题是我使用的这个 Tab 手势 有时不起作用(大约 5 次测试 = 1 次错误)。

在 DEBUG 期间出现问题时,我看到仍然可以识别 Tab 键,但它在我设置的操作中没有响应。

它发生在 iOS 和 Android 设备上。

这是我的 XAML 代码:

<RelativeLayout>
    <Image Source="icon_question" WidthRequest="15" HeightRequest="15"></Image>
    <Label Margin="15, -3, 0, 0" HorizontalOptions="CenterAndExpand" HorizontalTextAlignment="Center" 
           Text="Some text" TextColor="Blue" FontSize="15"  TextDecorations="Underline">
        <Label.GestureRecognizers>
            <TapGestureRecognizer Tapped="_tabLinkForgetPassword"></TapGestureRecognizer>
        </Label.GestureRecognizers>
    </Label>
</RelativeLayout>

下面是我的代码:

private void _tabLinkForgetPassword(object s, EventArgs e)
{
  App.Current.MainPage = new ResetPasswordPage(false);
}

我希望选项卡每次都响应,而不仅仅是像这样的时候。感谢您的帮助。

如 AndroDevil 所述,您必须处理父项上的点击手势(Grid、StackLayout、ContentView,无论您想要什么)。在你的情况下,你为什么不使用 Relative layout ?因此,您可以点击标签或图像。

当你认为它不起作用时,只是当你点击空的 space 时:字符之间(或者甚至在像 O 这样的字符的空隙中(但承认这一点,有点很难点击文本的那几个像素))。

最后,您不需要设置 NumberOfTapsRequired,因为据我所知,它是默认值。