From c2876ee7585025c0ea6cbbd78e97438ffb79e608 Mon Sep 17 00:00:00 2001 From: jr Date: Thu, 9 Jul 2015 15:20:11 +0200 Subject: [PATCH] Added "NoLeftClickDelay" TaskbarIcon dependency property, to optionally make left clicks work without delay. --- .../NotifyIconWpf/TaskbarIcon.Declarations.cs | 27 +++++++++++++++++++ .../Source/NotifyIconWpf/TaskbarIcon.cs | 14 +++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.Declarations.cs b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.Declarations.cs index a12c56e..d7157d9 100644 --- a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.Declarations.cs +++ b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.Declarations.cs @@ -828,6 +828,33 @@ namespace Hardcodet.Wpf.TaskbarNotification #endregion + #region NoLeftClickDelay dependency property + + /// + /// Set to true to make left clicks work without delay. + /// + public static readonly DependencyProperty NoLeftClickDelayProperty = + DependencyProperty.Register("NoLeftClickDelay", + typeof(bool), + typeof(TaskbarIcon), + new FrameworkPropertyMetadata(false)); + + + /// + /// A property wrapper for the + /// dependency property:
+ /// Set to true to make left clicks work without delay. + ///
+ [Category(CategoryName)] + [Description("Set to true to make left clicks work without delay.")] + public bool NoLeftClickDelay + { + get { return (bool)GetValue(NoLeftClickDelayProperty); } + set { SetValue(NoLeftClickDelayProperty, value); } + } + + #endregion + //EVENTS #region TrayLeftMouseDown diff --git a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs index 884eedc..f24b65c 100644 --- a/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs +++ b/Hardcodet.NotifyIcon.Wpf/Source/NotifyIconWpf/TaskbarIcon.cs @@ -67,6 +67,14 @@ namespace Hardcodet.Wpf.TaskbarNotification /// private readonly Timer singleClickTimer; + /// + /// The time we should wait for a double click. + /// + private int doubleClickWaitTime + { + get { return NoLeftClickDelay ? 0 : WinApi.GetDoubleClickTime(); } + } + /// /// A timer that is used to close open balloon tooltips. /// @@ -409,7 +417,7 @@ namespace Hardcodet.Wpf.TaskbarNotification LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowTrayPopup(cursorPosition); }; - singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); + singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite); isLeftClickCommandInvoked = true; } else @@ -431,7 +439,7 @@ namespace Hardcodet.Wpf.TaskbarNotification LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); ShowContextMenu(cursorPosition); }; - singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); + singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite); isLeftClickCommandInvoked = true; } else @@ -450,7 +458,7 @@ namespace Hardcodet.Wpf.TaskbarNotification { LeftClickCommand.ExecuteIfEnabled(LeftClickCommandParameter, LeftClickCommandTarget ?? this); }; - singleClickTimer.Change(WinApi.GetDoubleClickTime(), Timeout.Infinite); + singleClickTimer.Change(doubleClickWaitTime, Timeout.Infinite); } }