我想控制用户在用鼠标单击时是单击还是双击。所以我使用这段代码:
private void MouseSingleClickCommand(RoutedEventArgs e)
{
_dtMouseClick.Start();
}
private void MouseClick_Tick(object sender, System.EventArgs e)
{
_dtMouseClick.Stop();
//my one click code
}
private void MouseDoubleClickCommand(MouseButtonEventArgs e)
{
_dtMouseClick.Stop();
//code of the double click
}
_dt 是在视图模型的构造函数中创建的 DispatcherTimer:
_dtMouseClick =
new System.Windows.Threading.DispatcherTimer(
new TimeSpan(0, 0, 0, 0, 200),
System.Windows.Threading.DispatcherPriority.Background,
MouseClick_Tick,
System.Windows.Threading.Dispatcher.CurrentDispatcher);
但是,由于调度程序没有停止,因此始终执行一键式代码。
为什么?。
谢谢。
编辑:我包括按钮的 axml:
<StackPanel Height="Auto" HorizontalAlignment="Left" Margin="548,0,0,0" Name="stpBotnoesBasicos" VerticalAlignment="Top" Width="Auto">
<Button Content="Buscar" Height="23" Name="btn01" Width="75">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cmd:EventToCommand Command="{Binding MouseSingleClickCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
<i:EventTrigger EventName="MouseDoubleClick">
<cmd:EventToCommand Command="{Binding MouseDoubleClickCommand}" PassEventArgsToCommand="True"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
</Stackpannel>