PanGesture and TapGesture together in a ListView Cell

Seb_GlanumSeb_Glanum Member ✭✭
edited September 2019 in Xamarin.Forms

Hello everyone,

I have a ListView where i'm putting a Pangesture to do swipe on each cells. My issue is that I have an area (Grid) on my cell where I need to put a TapGesture but it is not working, TapGesture method is never called. Why is it get cancelled ? I have also a button which is work perfectly with PanGesture. Why TapGesture and Button doesn't have the same behaviour ?

Thanks !

Best Answer


  • LandLuLandLu Member, Xamarin Team Xamurai
    edited September 2019

    PanGesture and TapGesture can both work even though you added them in a single control. Here is my list view's item template:

                    <!--<Grid HeightRequest="100" BackgroundColor="Red">
                            <PanGestureRecognizer PanUpdated="PanGestureRecognizer_PanUpdated"/>
                        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
                        <PanGestureRecognizer PanUpdated="PanGestureRecognizer_PanUpdated"/>

    They all work fine no matter I placed the PanGestureRecognizer in StackLayout or Grid.

  • Seb_GlanumSeb_Glanum Member ✭✭
    edited September 2019

    Okay I understand what is happening.

    So in this ViewCell I have a Grid where I put two StackLayout side by side (Horizontal) and there is first Stack visible at the begginning when you open this page. And the other is not visible because I have put a TranslationX. If i'm swipping with PanGesture I modify the TranslationX of my Grid in which there are these two stacks to appear along the way my second stack and disappear my first one.

    I think moving children with TranslationX seems to cancel TapGesture.

  • LandLuLandLu Member, Xamarin Team Xamurai

    How did you change one stacklayout's TranslationX through another stacklayout's Tap Gesture?
    Could you share a sample?

  • Seb_GlanumSeb_Glanum Member ✭✭
    edited September 2019

    Sorry this not what I meant, I'm not changing first StackLayout TranslationX with TapGesture. I'm using PanGesture with e.TotalX to atrribute a new value of my TranslationX to modify the position of my grid where the childrens are these two stacklayout.

    The issue here is that when I'm swipping to my second stack, the TapGesture I have put on this layout doesn't work.

    I have found another thread similar to my issue :

  • LandLuLandLu Member, Xamarin Team Xamurai

    If your second stack layout moves to the position of your first layout it will overlap the first stack layout.
    Then your first stack layout's tap gesture will be intercepted. But I'm not sure what happened on your side so I need your code to help me reproduce your issue.

  • Seb_GlanumSeb_Glanum Member ✭✭

    Here is a project sample of my issue.
    You can run it on iOS don't try it on Android it will be not working.

  • Seb_GlanumSeb_Glanum Member ✭✭

    Okay I see i'm going to fix it, thank you for your help and your time !

Sign In or Register to comment.