From 211929a488af5f3803c9f91ad8f612e6a8b98b0d Mon Sep 17 00:00:00 2001 From: punker76 Date: Mon, 7 Oct 2024 09:52:47 +0200 Subject: [PATCH] feature: #36 add BalloonClosed event for custom balloon --- src/NotifyIconWpf/TaskbarIcon.Declarations.cs | 44 +++++++++++++++++++ src/NotifyIconWpf/TaskbarIcon.cs | 2 + 2 files changed, 46 insertions(+) diff --git a/src/NotifyIconWpf/TaskbarIcon.Declarations.cs b/src/NotifyIconWpf/TaskbarIcon.Declarations.cs index 378a851..fe033ac 100644 --- a/src/NotifyIconWpf/TaskbarIcon.Declarations.cs +++ b/src/NotifyIconWpf/TaskbarIcon.Declarations.cs @@ -1949,6 +1949,50 @@ internal static RoutedEventArgs RaiseBalloonClosingEvent(DependencyObject target #endregion + #region BalloonClosed + + /// + /// BalloonClosed Attached Routed Event + /// + public static readonly RoutedEvent BalloonClosedEvent = EventManager.RegisterRoutedEvent("BalloonClosed", + RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(TaskbarIcon)); + + /// + /// Adds a handler for the BalloonClosed attached event + /// + /// UIElement or ContentElement that listens to the event + /// Event handler to be added + public static void AddBalloonClosedHandler(DependencyObject element, RoutedEventHandler handler) + { + RoutedEventHelper.AddHandler(element, BalloonClosedEvent, handler); + } + + /// + /// Removes a handler for the BalloonClosed attached event + /// + /// UIElement or ContentElement that listens to the event + /// Event handler to be removed + public static void RemoveBalloonClosedHandler(DependencyObject element, RoutedEventHandler handler) + { + RoutedEventHelper.RemoveHandler(element, BalloonClosedEvent, handler); + } + + /// + /// A static helper method to raise the BalloonClosed event on a target element. + /// + /// UIElement or ContentElement on which to raise the event + /// The instance that manages the balloon. + internal static RoutedEventArgs RaiseBalloonClosedEvent(DependencyObject target, TaskbarIcon source) + { + if (target == null) return null; + + RoutedEventArgs args = new RoutedEventArgs(BalloonClosedEvent, source); + RoutedEventHelper.RaiseEvent(target, args); + return args; + } + + #endregion + //ATTACHED PROPERTIES #region ParentTaskbarIcon diff --git a/src/NotifyIconWpf/TaskbarIcon.cs b/src/NotifyIconWpf/TaskbarIcon.cs index 84ae7f1..8d7cf4b 100644 --- a/src/NotifyIconWpf/TaskbarIcon.cs +++ b/src/NotifyIconWpf/TaskbarIcon.cs @@ -317,6 +317,8 @@ public void CloseBalloon() // close the popup popup.IsOpen = false; + RaiseBalloonClosedEvent(element, this); + // remove the reference of the popup to the balloon in case we want to reuse // the balloon (then added to a new popup) popup.Child = null;