Skip to content

This project shows how you can capture gestures not yet supported out of the box in Xamarin.Forms.

Notifications You must be signed in to change notification settings

chrispy2day/Xamarin-Gestures-Demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Gestures in Xamarin.Forms

Gestures are a vital part to any mobile application. We've all become very familiar with swiping, pinching, tapping, dragging, etc. to perform all our common mobile app tasks. In fact, how many of you have found yourself trying these gestures on a non-touch screen only to remember, "Blast! This doesn't have touch!" Yep, me too...

So we need to support gestures, but unfortunately the current version of Xamarin.Forms is pretty lacking in this area, only supporting taps. Thankfully, with all the extensibility it isn't too difficult to extend the platform and create support for the gestures that you need. I've been working on this recently and I've seen quite a bit of confusion around this area, so I thought I would create this project to demo one approach to tackling this problem.

Implementation

First off, let me give a heap of credit to Rob Gibbens for getting me started. If you haven't already, definitely check out his post on the same topic as I am not going to repeat the code explanation, just extend upon it. Another very helpful project is SimpleCustomGestureFrame. I actually found this after I started my own implementation, but used nearly identical code and refactored mine to follow his implementation pattern. There, credit given where it's due. Thanks guys for the wonderful starting point!

Now then, my implementation is slightly different because I chose to extend a ContentView, mostly because I just wanted a basically empty area to receive and act upon swipe gestures. Obviously, you should start from whatever control will work best in your situation. I also added in support for Windows Phone. In this case I didn't see a native control being created for the ContentView (maybe I'm missing something here), so after some fiddling I decided to just inject my own native control for the gesture listener. For the majority of controls that you will be inheriting from this would not be necessary because there will already be a native control you can access. The gesture listening code would then be the same.

For the purposes of this demo, I'm just binding a simple label to give feedback on swipes received (my gesture of choice). You could absolutely extend this and listen to more gestures and you can see the previously mentioned projects for examples on how to do that. Do note that I'm using Fody PropertyChanged on the view model. You certainly don't have to, I just like saving myself some keystrokes and I think it makes the code more readable then implementing INotifyPropertyChanged everywhere, but to each their own.

About

This project shows how you can capture gestures not yet supported out of the box in Xamarin.Forms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages