Reputation: 3681
I am trying to implement a keypad UI. In the keypad, the +(plus) and 0(zero) options are placed on a single image icon. So I need to show 0 on UI for single tap and for double tap I need to show the + on UI.
My Code
<Image
Grid.Column="1"
Source="ic_zero_xx.png"
Style="{StaticResource KeypadImageStyle}">
<Image.GestureRecognizers>
<TapGestureRecognizer
Tapped="ZeroTapped"
NumberOfTapsRequired="1">
</TapGestureRecognizer>
</Image.GestureRecognizers>
</Image>
private void ZeroTapped(object sender, EventArgs e)
{
phonenumber_label.Text = "0";
}
How I can mention 2 different taps at the same time on an image?
Upvotes: 1
Views: 648
Reputation: 14475
We can add two TapGestureRecognizer
on that image, one for single tap and the other for double tap .
<Image >
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Single" NumberOfTapsRequired="1"/>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Double" NumberOfTapsRequired="2"/>
</Image.GestureRecognizers>
</Image>
private void TapGestureRecognizer_Single(object sender, EventArgs e)
{
label.Text = "0";
}
private void TapGestureRecognizer_Double(object sender, EventArgs e)
{
label.Text = "+";
}
Upvotes: 2
Reputation: 318
I think you can use a timer If user tap twice within 150ms then it is a double tap.
int Tapped=0;
private void ZeroTapped(object sender,EventArgs e)
{
if(Tapped==0)
{
Device.StartTime(TimeSpan.FromMillSeconds(150),()=>
{
if(Tapped=1)
{
//1 tap.
}
else
{
//double tap.
}
Tapped=0;
return false;
}
}
else
{
Tapped++;
}
}
Upvotes: 0