From f5c5821a8c74d0bd9a52b198f180998f172fb264 Mon Sep 17 00:00:00 2001 From: Nick Guo Date: Tue, 30 Sep 2025 18:26:54 +0800 Subject: [PATCH] Add BalloonTipClicked Event to NotifyIcon --- .../Controls/Other/NotifyIcon.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs index b46d0cdc..fbbfa8dd 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -36,6 +36,8 @@ public class NotifyIcon : FrameworkElement, IDisposable private const int WmTrayMouseMessage = InteropValues.WM_USER + 1024; + private const int NIN_BALLOONUSERCLICK = InteropValues.WM_USER + 1025; + private string _windowClassName; private int _wmTaskbarCreated; @@ -574,7 +576,9 @@ public class NotifyIcon : FrameworkElement, IDisposable _dispatcherTimerPos.Interval = TimeSpan.FromMilliseconds(200); _dispatcherTimerPos.Start(); } - + break; + case NIN_BALLOONUSERCLICK: + RaiseEvent(new RoutedEventArgs(BalloonTipClickedEvent)); break; } } @@ -672,6 +676,15 @@ public class NotifyIcon : FrameworkElement, IDisposable remove => RemoveHandler(MouseDoubleClickEvent, value); } + public static readonly RoutedEvent BalloonTipClickedEvent = + EventManager.RegisterRoutedEvent("BalloonTipClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(NotifyIcon)); + + public event RoutedEventHandler BalloonTipClicked + { + add { AddHandler(BalloonTipClickedEvent, value); } + remove { RemoveHandler(BalloonTipClickedEvent, value); } + } + private void UpdateDataContext(FrameworkElement target, object oldValue, object newValue) { if (target == null || BindingOperations.GetBindingExpression(target, DataContextProperty) != null) return;