How to detect Left swipe and Right swipe for Stacklayout in Xamarin.Forms?

11,910

Solution 1

I have done sample repo on GitHub, let me know what do you think? https://github.com/tkowalczyk/SimpleCustomGestureFrame

Solution 2

StackLayout like all the other layout classes doesn't have a renderer, since the layout is completely handled by Xamarin.Forms itself without any help of native layout engines.

What you might do to achieve what you're looking for is to implement a custom renderer for a Frame and implement your swipe gestures on it. You could then put your StackLayout into the Frame and you should be settled.

Share:
11,910
Femil Shajin
Author by

Femil Shajin

I Just wanna know more!!

Updated on June 27, 2022

Comments

  • Femil Shajin
    Femil Shajin almost 2 years

    I have been trying to detect left swipe and right swipe for stacklayout. Things in which I need help are,

    1. Creating a stacklayout renderer to add swipe Gesture.
    2. How to detect user has swiped left or right.

    Please provide a solution which works on cross platforms.

    Providing an example for stacklayout renderer will be really helpful to acheive the swipe functionality in xamarin.forms

  • Femil Shajin
    Femil Shajin over 9 years
    Itz good. It serves the purpose. Thanks for your repo. Very Useful one, But have to tried to detect swipe inside carasoul page?? Horizontal scroll is not being detected in carasoul page coz it already has swipe gesture. Just shared this fact because I noticed it.. Disabling the gesture of carasoul will solve this problem.. Again Thanks.. :)
  • Rodolfo De Los Santos
    Rodolfo De Los Santos over 8 years
    I had to override DispatchTouchEvent and call the the GestureDetector from there to get it to work. public override bool DispatchTouchEvent(MotionEvent e) { _detector.OnTouchEvent(e); return base.DispatchTouchEvent(e); }
  • Marek
    Marek almost 7 years
    Rodolfo De Los Santos :+1: