1

Possible Duplicate:
WPF: Button single click + double click problem
WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?

I need to to handle both the single click and the double click of a button in a WPF application with different reaction. On one click I only want to show that button has focus and on double click I want to show a new window(similar to Windows icon behavior). But on a doubleclick, WPF fires two clicks so it's hard to handle this situation. Can anyone help to solve this problem? Thanks for any help.

I tried this:

private static DispatcherTimer myClickWaitTimer = 
    new DispatcherTimer(
        new TimeSpan(0, 0, 0, 1), 
        DispatcherPriority.Background, 
        mouseWaitTimer_Tick, 
        Dispatcher.CurrentDispatcher);

private void Button_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    // Stop the timer from ticking.
    myClickWaitTimer.Stop();

    Trace.WriteLine("Double Click");
    e.Handled = true;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
    myClickWaitTimer.Start();
}

private static void mouseWaitTimer_Tick(object sender, EventArgs e)
{
    myClickWaitTimer.Stop();

    // Handle Single Click Actions
            MainWindow c = new MainWindow()
    c.focusButton.Background = new SolidColorBrush(Colors.DarkBlue);
}

but focusButton Bacground didn´t change when I clicked on the focusButton.

Community
  • 1
  • 1
  • Also, though this is for Windows Forms, the second example from this MSDN link may help: http://msdn.microsoft.com/en-us/library/ms171543%28v=vs.110%29.aspx – Daniel Castro Nov 10 '12 at 20:36
  • another double click question http://stackoverflow.com/questions/1293530/how-to-bind-a-command-in-wpf-to-a-double-click-event-handler-of-a-control – Glenn Ferrie Nov 10 '12 at 20:39

1 Answers1

0

Interesting question. In my opinion, on the first step you have to handle Button_click in different ways as usual. Maybe try to use some counter and timer?

Gayot Fow
  • 8,710
  • 1
  • 35
  • 48
Marek Urbanowicz
  • 12,659
  • 16
  • 62
  • 87