Skip to content

Commit 927ce7f

Browse files
author
Eric Rodewald
committed
Add PopupOpened/PopupClosed events to PopupBox
1 parent 1390b36 commit 927ce7f

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,24 @@ private static void IsPopupOpenPropertyChangedCallback(DependencyObject dependen
242242
else
243243
Mouse.Capture(null);
244244
}
245-
245+
if (newValue)
246+
{
247+
var popupOpenedEventArgs = new RoutedEventArgs()
248+
{
249+
RoutedEvent = PopupOpenedEvent,
250+
Source = popupBox
251+
};
252+
popupBox.RaiseEvent(popupOpenedEventArgs);
253+
}
254+
else
255+
{
256+
var popupClosedEventArgs = new RoutedEventArgs()
257+
{
258+
RoutedEvent = PopupClosedEvent,
259+
Source = popupBox
260+
};
261+
popupBox.RaiseEvent(popupClosedEventArgs);
262+
}
246263

247264
popupBox.AnimateChildrenIn(!newValue);
248265
popupBox._popup?.RefreshPosition();
@@ -259,6 +276,45 @@ public bool IsPopupOpen
259276
set { SetValue(IsPopupOpenProperty, value); }
260277
}
261278

279+
/// <summary>
280+
/// Event corresponds to the popup opening
281+
/// </summary>
282+
public static readonly RoutedEvent PopupOpenedEvent =
283+
EventManager.RegisterRoutedEvent(
284+
"PopupOpened",
285+
RoutingStrategy.Bubble,
286+
typeof(RoutedEventHandler),
287+
typeof(PopupBox));
288+
289+
/// <summary>
290+
/// Event corresponds to the popup closing
291+
/// </summary>
292+
public static readonly RoutedEvent PopupClosedEvent =
293+
EventManager.RegisterRoutedEvent(
294+
"PopupClosed",
295+
RoutingStrategy.Bubble,
296+
typeof(RoutedEventHandler),
297+
typeof(PopupBox));
298+
299+
/// <summary>
300+
/// Add / Remove PopupOpenedEvent handler
301+
/// </summary>
302+
public event RoutedEventHandler PopupOpened
303+
{
304+
add { AddHandler(PopupOpenedEvent, value); }
305+
remove { RemoveHandler(PopupOpenedEvent, value); }
306+
}
307+
308+
/// <summary>
309+
/// Add / Remove PopupClosedEvent handler
310+
/// </summary>
311+
public event RoutedEventHandler PopupClosed
312+
{
313+
add { AddHandler(PopupClosedEvent, value); }
314+
remove { RemoveHandler(PopupClosedEvent, value); }
315+
}
316+
317+
262318
public static readonly DependencyProperty StaysOpenProperty = DependencyProperty.Register(
263319
nameof(StaysOpen), typeof (bool), typeof (PopupBox), new PropertyMetadata(default(bool)));
264320

0 commit comments

Comments
 (0)