@@ -242,31 +242,18 @@ private static void IsPopupOpenPropertyChangedCallback(DependencyObject dependen
242
242
else
243
243
Mouse . Capture ( null ) ;
244
244
}
245
-
246
- if ( newValue )
247
- {
248
- var popupOpenedEventArgs = new RoutedEventArgs ( )
249
- {
250
- RoutedEvent = OnPopupOpenedEvent ,
251
- Source = popupBox
252
- } ;
253
- popupBox . RaiseEvent ( popupOpenedEventArgs ) ;
254
- }
255
- else
256
- {
257
- var popupClosedEventArgs = new RoutedEventArgs ( )
258
- {
259
- RoutedEvent = OnPopupClosedEvent ,
260
- Source = popupBox
261
- } ;
262
- popupBox . RaiseEvent ( popupClosedEventArgs ) ;
263
- }
264
-
245
+
265
246
popupBox . AnimateChildrenIn ( ! newValue ) ;
266
247
popupBox . _popup ? . RefreshPosition ( ) ;
267
248
268
249
VisualStateManager . GoToState ( popupBox , newValue ? PopupIsOpenStateName : PopupIsClosedStateName , true ) ;
269
- }
250
+
251
+ if ( newValue )
252
+ popupBox . OnOpened ( ) ;
253
+ else
254
+ popupBox . OnClosed ( ) ;
255
+
256
+ }
270
257
271
258
/// <summary>
272
259
/// Gets or sets whether the popup is currently open.
@@ -275,46 +262,7 @@ public bool IsPopupOpen
275
262
{
276
263
get { return ( bool ) GetValue ( IsPopupOpenProperty ) ; }
277
264
set { SetValue ( IsPopupOpenProperty , value ) ; }
278
- }
279
-
280
- /// <summary>
281
- /// Event corresponds to the popup opening
282
- /// </summary>
283
- public static readonly RoutedEvent OnPopupOpenedEvent =
284
- EventManager . RegisterRoutedEvent (
285
- "OnPopupOpened" ,
286
- RoutingStrategy . Bubble ,
287
- typeof ( RoutedEventHandler ) ,
288
- typeof ( PopupBox ) ) ;
289
-
290
- /// <summary>
291
- /// Event corresponds to the popup closing
292
- /// </summary>
293
- public static readonly RoutedEvent OnPopupClosedEvent =
294
- EventManager . RegisterRoutedEvent (
295
- "OnPopupClosed" ,
296
- RoutingStrategy . Bubble ,
297
- typeof ( RoutedEventHandler ) ,
298
- typeof ( PopupBox ) ) ;
299
-
300
- /// <summary>
301
- /// Add / Remove OnPopupOpenedEvent handler
302
- /// </summary>
303
- public event RoutedEventHandler OnPopupOpened
304
- {
305
- add { AddHandler ( OnPopupOpenedEvent , value ) ; }
306
- remove { RemoveHandler ( OnPopupOpenedEvent , value ) ; }
307
- }
308
-
309
- /// <summary>
310
- /// Add / Remove OnPopupClosedEvent handler
311
- /// </summary>
312
- public event RoutedEventHandler OnPopupClosed
313
- {
314
- add { AddHandler ( OnPopupClosedEvent , value ) ; }
315
- remove { RemoveHandler ( OnPopupClosedEvent , value ) ; }
316
- }
317
-
265
+ }
318
266
319
267
public static readonly DependencyProperty StaysOpenProperty = DependencyProperty . Register (
320
268
nameof ( StaysOpen ) , typeof ( bool ) , typeof ( PopupBox ) , new PropertyMetadata ( default ( bool ) ) ) ;
@@ -388,7 +336,6 @@ public Orientation UnfurlOrientation
388
336
[ Category ( "Behavior" ) ]
389
337
public event RoutedEventHandler ToggleCheckedContentClick { add { AddHandler ( ToggleCheckedContentClickEvent , value ) ; } remove { RemoveHandler ( ToggleCheckedContentClickEvent , value ) ; } }
390
338
391
-
392
339
/// <summary>
393
340
/// Raises <see cref="ToggleCheckedContentClickEvent"/>.
394
341
/// </summary>
@@ -398,6 +345,56 @@ protected virtual void OnToggleCheckedContentClick()
398
345
RaiseEvent ( newEvent ) ;
399
346
}
400
347
348
+ public static readonly RoutedEvent OpenedEvent =
349
+ EventManager . RegisterRoutedEvent (
350
+ "Opened" ,
351
+ RoutingStrategy . Bubble ,
352
+ typeof ( EventHandler ) ,
353
+ typeof ( PopupBox ) ) ;
354
+
355
+ /// <summary>
356
+ /// Raised when the popup is opened.
357
+ /// </summary>
358
+ public event RoutedEventHandler Opened
359
+ {
360
+ add { AddHandler ( OpenedEvent , value ) ; }
361
+ remove { RemoveHandler ( OpenedEvent , value ) ; }
362
+ }
363
+
364
+ /// <summary>
365
+ /// Raises <see cref="OpenedEvent"/>.
366
+ /// </summary>
367
+ protected virtual void OnOpened ( )
368
+ {
369
+ var newEvent = new RoutedEventArgs ( OpenedEvent , this ) ;
370
+ RaiseEvent ( newEvent ) ;
371
+ }
372
+
373
+ public static readonly RoutedEvent ClosedEvent =
374
+ EventManager . RegisterRoutedEvent (
375
+ "Closed" ,
376
+ RoutingStrategy . Bubble ,
377
+ typeof ( EventHandler ) ,
378
+ typeof ( PopupBox ) ) ;
379
+
380
+ /// <summary>
381
+ /// Raised when the popup is opened.
382
+ /// </summary>
383
+ public event RoutedEventHandler Closed
384
+ {
385
+ add { AddHandler ( ClosedEvent , value ) ; }
386
+ remove { RemoveHandler ( ClosedEvent , value ) ; }
387
+ }
388
+
389
+ /// <summary>
390
+ /// Raises <see cref="ClosedEvent"/>.
391
+ /// </summary>
392
+ protected virtual void OnClosed ( )
393
+ {
394
+ var newEvent = new RoutedEventArgs ( ClosedEvent , this ) ;
395
+ RaiseEvent ( newEvent ) ;
396
+ }
397
+
401
398
public override void OnApplyTemplate ( )
402
399
{
403
400
if ( _popup != null )
0 commit comments