Reputation: 2085
I have found a strange tap issue in my app. I have 42 buttons arranged 6x7 in the form of a calendar. Every button has calls the same function OnDoubleTap which is the one of the events of a button.
The problem is, successive taps on two buttons is treated as a double tap on the second tapped button.
public void OnButtonDoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
{
// function
}
this function is associated with all the 42 buttons through the xaml code like this
<Button x:Name="b00" Content="" Height="60" Width="68" MinWidth="68" MinHeight="60" Click="OnClick" DoubleTap="OnButtonDoubleTap" Foreground="#FF171717" BorderThickness="0" Hold="OnButtonLongPress" Style="{StaticResource DateButtonTemplate}" FontFamily="{StaticResource CicleFina}" />
<Button x:Name="b01" Content="" Height="60" Canvas.Left="68" Width="68" MinWidth="68" MinHeight="60" Click="OnClick" DoubleTap="OnButtonDoubleTap" Hold="OnButtonLongPress" Foreground="#FF171717" BorderThickness="0" Style="{StaticResource DateButtonTemplate}" FontFamily="{StaticResource CicleFina}"/>
<Button x:Name="b02" Content="" Height="60" Canvas.Left="136" Width="68" MinWidth="68" MinHeight="60" Click="OnClick" DoubleTap="OnButtonDoubleTap" Hold="OnButtonLongPress" Foreground="#FF171717" BorderThickness="0" Style="{StaticResource DateButtonTemplate}" FontFamily="{StaticResource CicleFina}"/>
<Button x:Name="b03" Content="" Height="60" Canvas.Left="204" Width="68" MinWidth="68" MinHeight="60" Click="OnClick" DoubleTap="OnButtonDoubleTap" Hold="OnButtonLongPress" Foreground="#FF171717" BorderThickness="0" Style="{StaticResource DateButtonTemplate}" FontFamily="{StaticResource CicleFina}"/>
<Button x:Name="b04" Content="" Height="60" Canvas.Left="272" Width="68" MinWidth="68" MinHeight="60" Click="OnClick" DoubleTap="OnButtonDoubleTap" Hold="OnButtonLongPress" Foreground="#FF171717" BorderThickness="0" Style="{StaticResource DateButtonTemplate}" FontFamily="{StaticResource CicleFina}"/>
Any idea why this is happening?
Alfah
Upvotes: 0
Views: 1209
Reputation: 2085
I have solved the problem by capturing the first click and the second click. Check the names of the sender and do the function only if both has the same.
The first click is captured on the OnClick function and the second at the OnDoubleTap function
public void OnClick(object sender, RoutedEventArgs e)
{
Button nbut = sender as Button;
m_captureFirstClick = nbut.Name;
}
public void OnButtonDoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
{
Button temp = sender as Button;
if (temp.Name == m_captureFirstClick)
{
// do what you want to do
}
}
Alfah
Upvotes: 1