I have Xamarin Forms project and on my page there is this code:
<Image Source="genea_login_logo.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LogoCommand}" NumberOfTapsRequired="2" />
</Image.GestureRecognizers>
</Image>
It works as expected. However when I change NumberOfTapsRequired from 2 to 5, it doesn't work any more. Is this behaviour expected? Is it possible to implement 5-click command?
Edit: This is only on Android.
TapGestureRecognizer with more than 2 NumberOfTapsRequired doesn't work, actually, in Android. You can implement some kind of logic to achieve this effect.
In XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Demo.Views.MainPage"
Title="MainPage">
<Grid HorizontalOptions="Center" VerticalOptions="Center">
<Image Source="icon.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_OnTapped"/>
</Image.GestureRecognizers>
</Image>
</Grid>
</ContentPage>
Code behind....
private DateTime? LastTap = null;
private byte NumberOfTaps = 0;
private const int NumberOfTapsRequired = 3;
private const int ToleranceInMs = 1000;
private async void TapGestureRecognizer_OnTapped(object sender, EventArgs e)
{
if (LastTap == null || (DateTime.Now - LastTap.Value).TotalMilliseconds < ToleranceInMs)
{
if (NumberOfTaps == (NumberOfTapsRequired - 1))
{
await App.Current.MainPage.DisplayAlert("Hi", "Hi from Gesture", "Ok");
NumberOfTaps = 0;
LastTap = null;
return;
}
else
{
NumberOfTaps++;
LastTap = DateTime.Now;
}
}
else
{
NumberOfTaps=1;
LastTap = DateTime.Now;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With