Add BalloonTipClicked Event to NotifyIcon

This commit is contained in:
Nick Guo authored and NaBian committed 2025-10-01 23:45:18 +08:00
1 parent 0084f9a24d
commit f5c5821a8c
1 file changed
+15 -2
@@ -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;