Every mobile platform provides us with a way of handling gestures. The approach is not the same for each platform, but the point is the same: accept touch events from the user.
Xamarin.Forms, as of this writing, has cross-platform support for the tap gesture, but worry not, view renderers come to the rescue once again. In this recipe, we will demonstrate how to add long press behavior to BoxView
. The equivalent for each platform is iOS CGContext
, Android ViewGroup
, and Rectangle
for the Windows Phone equivalent.
Create a Xamarin cross-platform application using Visual Studio. Xamarin Studio works too of course; just add the Windows platform if you need to use Visual Studio later. Let's give it the name
XamFormsPlatformGesture
.In the PCL project, right-click and Add | New Item…, choose Forms Xaml Page, and name it
MainPage
.In the
App.cs
constructor, change the assignment of theMainPage
property with a new instance of our newly createdMainPage...