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.