Windows手机双击问题

时间:2011-12-05 11:16:44

标签: button windows-phone-7 double-click

我在我的应用中发现了一个奇怪的点击问题。我有42个按钮,以日历的形式排列为6x7。每个按钮都调用相同的函数OnDoubleTap,这是一个按钮的事件之一。

问题是,两个按钮上的连续点击被视为第二个点击按钮上的双击。

public void OnButtonDoubleTap(object sender, System.Windows.Input.GestureEventArgs e)
{
       // function
}

此功能通过xaml代码与所有42个按钮相关联,如此

<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}"/>

知道为什么会这样吗?

Alfah

1 个答案:

答案 0 :(得分:1)

我通过捕获第一次点击和第二次点击解决了这个问题。 检查发件人的姓名,只有两者具有相同的功能才能执行此功能。

第一次点击是在OnClick功能上捕获的,第二次是在OnDoubleTap功能

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