Forum Xamarin Xamarin.Forms

TapGestureRecognizer in Image interfering with ViewCell Tapped event

Zzz96Zzz96 Member ✭✭
edited May 2018 in Xamarin.Forms

Adding a TapGestureRecognizer to an Image in a ViewCell prevents the ViewCell's Tapped event from firing on Android (iOS works). ContextActions (tap and hold) are unaffected. Here's the basic layout:

<ViewCell Tapped="OnViewCellClicked">
    <ViewCell.ContextActions>
        <MenuItem Text="Delete" Clicked="OnDeleteClicked" IsDestructive="True"/>
    </ViewCell.ContextActions>
    <StackLayout Orientation="Horizontal">
        <Label Text="Some Text" HorizontalOptions="StartAndExpand"/>
        <Image Source="image.png" HorizontalOptions="End" >
            <Image.GestureRecognizers> <!--Removing this allows OnViewCellClicked to be called with no issues-->
                <TapGestureRecognizer Tapped="OnImageTapped" NumberOfTapsRequired="1" />
            </Image.GestureRecognizers>
        </Image>
    </StackLayout>
</ViewCell>

P.S. The TapGestureRecognizer.Tapped event fires fine.

Answers

  • Zzz96Zzz96 Member ✭✭

    As a side note, adding another TapGestureRecognizer to the StackLayout works as an alternative to the ViewCell.Tapped event. Or should I say it worked. Before the Xamarin.Forms 3.0 update, I was actually able to use this approach but now accessing the ContextActions (tap and hold) also triggers the TapGestureRecognizer.Tapped event--which didn't use to be the case--so the two can't be used simultaneously. I considered making a separate post for this 3.0 issue but seeing that it would probably be ignored like the last issue I brought up I'll just mention it here.

  • FullEnglishFullEnglish GBMember ✭✭

    Experiencing the same issue since upgrading from XF 2.5 to 3.1.0

    There's a bug raised for it here: https://github.com/xamarin/Xamarin.Forms/issues/2180#issuecomment-404774958

Sign In or Register to comment.