Xamarin TapGestureRecognizer有时无法正常工作

问题描述 投票:0回答:1

我正在使用Xamarin.Forms构建我的移动应用程序,当我尝试在xaml标签上使用Xamarin.Forms gestures更特别是tap gesture时,我遇到了一个问题(在ios和android的平台上)。因为我想用这个标签作为链接。

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

在DEBUG期间出现问题时,我看到标签仍然被识别,但它在我设置的动作中没有响应。

它出现在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);
}

我希望标签每次响应,而不仅仅是这样的时间。我感谢你的帮助。

xaml xamarin xamarin.forms gesture uitapgesturerecognizer
1个回答
0
投票

正如AndroDevil所说,您必须处理父级(网格,StackLayout,ContentView,无论您想要什么)的点击手势。在你的情况下,你为什么不使用相对布局?因此,您可以点击标签或图像。

当你认为它不起作用时,就是当你点击空白区域时:在字符之间(或者甚至在像O这样的字符的空白内部(但承认它,很难点击那些几个像素))你的文字。

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

© www.soinside.com 2019 - 2024. All rights reserved.