I shared this solution, that is a mix between the two others solutions. I can't give the accepted solution to both, sorry.
If I use the PreviewMouseLeftButtonDown to control when is single click or double click works, instead of using two events (click and doubleclick).
So I solve the problem with this code:
This first method control the click with the mouse.
private void MouseLeftButtonDownCommand(MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
{
_dtMouseClick.Start();
}
else if(e.ClickCount > 1)
{
_dtMouseClick.Stop();
//the code of the double click
}
}
This method is the method that is linked to the DispatcherTimer, that is execute if is not stopped with the second click of the mouse.
private void MouseClick_Tick(object sender, System.EventArgs e)
{
_dtrMouseClick.Stop();
//code of the single click
}
The dispatcherTimer is create in the constructor of the view model
_dtBotonBuscarMouseClick =
new System.Windows.Threading.DispatcherTimer(
new TimeSpan(0, 0, 0, 0, 250),
System.Windows.Threading.DispatcherPriority.Background,
MouseClick_Tick,
System.Windows.Threading.Dispatcher.CurrentDispatcher);
_dtMouseClick.Stop();
The interval is 250ms that is the interval that is the time that the user has to double click.
In this solution, I use the same way to stop the dispatcherTimer, the stop() method, but for some reason if I use the two events (click and mouseDoubleClick) the dispatcherTimer is not stopped in the double click and if I use the MouseLeftButtonDown event the solution works.