Building a CustomRenderer for native gestures
Now we need to handle swipe left and right gestures for each mobile platform. Unfortunately, Xamarin.Forms
doesn't offer a cross-platform feature for swipe gestures, so we need to implement this ourselves. In order to do this, we are going to build a CustomRenderer
. Start by adding a new file to the Controls
folder called GestureView.cs
and implement the following:
public class GestureView : View { public event EventHandler SwipeLeft; public event EventHandler SwipeRight; public event EventHandler Touch; public void NotifySwipeLeft() { if (SwipeLeft != null) { SwipeLeft (this, EventArgs.Empty); } } public void NotifySwipeRight() { if (SwipeRight != null) { SwipeRight (this, EventArgs.Empty); } } public void NotifyTouch() { if (Touch != null) { Touch(this, EventArgs.Empty); } ...