1
可能重複:
WPF: Button single click + double click problem
WPF/MVVM - how to handle double-click on TreeViewItems in the ViewModel?WPF:如何處理點擊和雙擊按鈕?
我需要同時處理單點擊一個按鈕,在不同的反應WPF應用程序中的雙擊。單擊一次,我只想顯示該按鈕有焦點,雙擊我想顯示一個新窗口(類似於Windows圖標行爲)。但是在雙擊時,WPF會觸發兩次點擊,所以很難處理這種情況。任何人都可以幫助解決這個問題?謝謝你的幫助。
我嘗試這樣做:
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);
}
但focusButton Bacground didn't變化,當我點擊了focusButton。
此外,雖然這是針對Windows窗體的,但此MSDN鏈接的第二個示例可能有所幫助:http://msdn.microsoft.com/en-us/library/ms171543%28v=vs.110%29.aspx –
另一個雙擊問題http://stackoverflow.com/questions/1293530/how-to-bind-a-command-in-wpf-to-a-double-click-event-handler-of-a-control –