Custom Gestures In Xamarin Forms

Xamarin Forms only comes with a limited set of Gesture Recognizers, most notably the TapGestureRecognizer. Many times you will want more than just that and hence here is how you implement a custom gesture recognizer. In this example I will add the Pressed and Released events to a Xamarin Forms project.

Sample Project is located on Sample-XF-Gestures on GitHub

Create Xamarin Forms Gesture Recognizers

In our common project, we need to create our gesture recognizer for use in Xamarin Forms. I have done 2 examples of a PressedGestureRecognizer and ReleasedGestureRecognizer.

And the ReleasedGestureRecognizer the same again.

Add Custom Renderer

Next we need to a custom renderer for the control we want to add these gestures to. In this example I am using a Label.

UWP

Android

iOS

These renderers attach the native events to call the Command of the Gesture Recognizer.

Using Gesture Recognizer

Now that we have setup everything, we can now easily add the gesture recognizer to any labels.


Posted

in

by

Tags: