首页 > 解决方案 > Xamarin Forms Tap Gesture 两次点击专门导致对象引用未设置为对象实例

问题描述

奇怪的问题...但是,如果我特别尝试使用 2 次轻按,作为双击(快速轻按)来与我的页面交互,我会得到一个“对象引用未设置为对象的实例”。错误。

但是,如果我使用 1 NumberOfTapsRequired 或 3 NumberOfTapsRequired,一切正常。没有错误。代码按预期运行。

为什么特别是 2 次点击会引发错误?用手动计数器慢慢敲击不会产生错误。所以它特别是一些双击问题。

我还尝试在 Tapped 事件下使用计数器,然后在计算 2 次点击后调用代码。同样的问题。有点奇怪。

    <ContentPage.Content>
        <StackLayout BackgroundColor="Black" Padding="20,10,20,10">
            <Label x:Name="basemessage"  Text="Base Message"
                VerticalOptions="EndAndExpand" 
                HorizontalOptions="CenterAndExpand" BackgroundColor="Transparent" TextColor="White" FontSize="30">
                <Label.GestureRecognizers>
                    <TapGestureRecognizer x:Name="tappedmessage" NumberOfTapsRequired="1" Tapped="screentapped_Tapped"></TapGestureRecognizer>
                </Label.GestureRecognizers>
            </Label>
            <Label x:Name="itemslist"  Text="Items List"
                VerticalOptions="StartAndExpand" 
                HorizontalOptions="CenterAndExpand" BackgroundColor="Transparent" TextColor="White" FontSize="30">
                <Label.GestureRecognizers>
                    <TapGestureRecognizer x:Name="tappedlist" NumberOfTapsRequired="1" Tapped="screentapped_Tapped"></TapGestureRecognizer>
                </Label.GestureRecognizers>
            </Label>
            <Button x:Name="closedialog" Text="Continue..." TextTransform="None"
                VerticalOptions="End" 
                HorizontalOptions="CenterAndExpand" BackgroundColor="Transparent" TextColor="White" FontSize="25"
                Clicked="closedialog_Clicked"/>
        </StackLayout>
    </ContentPage.Content>

标签: .netxamlxamarin.forms

解决方案


推荐阅读