Home

Awesome

New version for MAUI here: https://github.com/vapolia/MauiGestures/

Below is version for Xamarin.Forms

Build status

NuGet
NuGet
Nuget

Supported Platforms

iOS, Android, UWP

Xamarin Form Gesture Effects

Add "advanced" gestures to Xamarin Forms. Available on all views. Most gesture commands include the event position.

    <Label Text="Click here" IsEnabled="True" ui:Gesture.TapCommand="{Binding OpenLinkCommand}" />

Or in code:

    var label = new Label();
    Vapolia.Lib.Ui.Gesture.SetTapCommand(label, new Command(() => { /*your code*/ }));

Quick start

Add the above nuget package to your Xamarin Forms project (only the netstandard one is enough).

In your platform projects (android,ios,uwp), before initializing xamarin forms, call Vapolia.Lib.Effects.PlatformGestureEffect.Init(); to force the discovery of this extension by the Xamarin Forms plugin engine.

The views on which the gesture is applied should have the property IsEnabled="True" and InputTransparent="False" which activates user interaction on them.

Examples

Add Gesture.TapCommand on any supported xaml view:

        <StackLayout ui:Gesture.TapCommand="{Binding OpenLinkCommand}">
            <Label Text="1.Tap this to open an url"  />
        </StackLayout>

Declare the corresponding namespace:

    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             ...
             xmlns:ui="clr-namespace:Vapolia.Lib.Ui;assembly=XamarinFormsGesture"
    >

And in the viewmodel:

 public Command OpenLinkCommand => new Command(() =>
 {
     //do something
 });

Supported Gestures

Properties:

Examples

Somme commands in XAML

<StackLayout ui:Gesture.TapCommand="{Binding OpenCommand}" IsEnabled="True">
    <Label Text="1.Tap this text to open an url" />
</StackLayout>

<StackLayout ui:Gesture.DoubleTapPointCommand="{Binding OpenPointCommand}" IsEnabled="True">
    <Label Text="2.Double tap this text to open an url" />
</StackLayout>

<BoxView
    ui:Gesture.PanPointCommand="{Binding PanPointCommand}"
    HeightRequest="200" WidthRequest="300"
    InputTransparent="False"
    IsEnabled="True"
     />

In the viewmodel:

public ICommand OpenCommand => new Command(async () =>
{
   //...
});

public ICommand OpenPointCommand => new Command<PointEventArgs>(point =>
{
    PanX = point.X;
    PanY = point.Y;
    //...
});

public ICommand PanPointCommand => new Command<PanEventArgs>(args =>
{
    var point = args.Point;
    PanX = point.X;
    PanY = point.Y;
    //...
});

Exemple in C# on a Grid containing an horizontal slider (set value on tap)

//Tap anywhere to set value
Gesture.SetTapPointCommand(this, new Command<PointEventArgs>(pt =>
{
    var delta = (pt.X - Padding.Left) / (Width - Padding.Left - Padding.Right);
    if(delta<0 || delta>1)
        return;
    Value = (int)Math.Round((Maximum - Minimum) * delta);
}));

Limitations

Only commands are supported (PR welcome for events). No .NET events. So you must use the MVVM pattern (https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/data_bindings_to_mvvm/).

Swipe commands are not supported on UWP due to a bug (event not received). If you find it, notify me! PinchCommand is not supported (yet) on UWP. PR welcome.

If your command is not receiving events, make sure that:

UWP requires fall creator update

Breaking changes

Version 3.3.3 has breaking changes:

Version 3.3.0 has breaking changes: