@@ -1510,7 +1510,7 @@ private void CreateWindow(bool asyncCall)
1510
1510
// cascading failure.
1511
1511
if ( PopupInitialPlacementHelper . IsPerMonitorDpiScalingActive )
1512
1512
{
1513
- DestroyWindow ( ) ;
1513
+ DestroyWindowImpl ( ) ;
1514
1514
_positionInfo = null ;
1515
1515
makeNewWindow = true ;
1516
1516
}
@@ -1601,18 +1601,40 @@ private void BuildWindow(Visual targetVisual)
1601
1601
_secHelper . BuildWindow ( origin . x , origin . y , targetVisual , IsTransparent , PopupFilterMessage , OnWindowResize , OnDpiChanged ) ;
1602
1602
}
1603
1603
1604
- private void DestroyWindow ( )
1604
+ /// <summary>
1605
+ /// Destroys the underlying window (HWND) if it is alive
1606
+ /// </summary>
1607
+ /// <returns>true if the window was destroyed, otherwise false</returns>
1608
+ private bool DestroyWindowImpl ( )
1605
1609
{
1606
1610
if ( _secHelper . IsWindowAlive ( ) )
1607
1611
{
1608
1612
_secHelper . DestroyWindow ( PopupFilterMessage , OnWindowResize , OnDpiChanged ) ;
1609
- ReleasePopupCapture ( ) ;
1613
+ return true ;
1614
+ }
1610
1615
1611
- // Raise closed event after popup has actually closed
1612
- OnClosed ( EventArgs . Empty ) ;
1616
+ return false ;
1617
+ }
1613
1618
1614
- // When closing, clear the placement target registration
1615
- UpdatePlacementTargetRegistration ( PlacementTarget , null ) ;
1619
+ /// <summary>
1620
+ /// Destroys the window, and does additional book-keeping
1621
+ /// like releasing the capture, raising Closed event, and
1622
+ /// clearing placement-target registration
1623
+ /// </summary>
1624
+ private void DestroyWindow ( )
1625
+ {
1626
+ if ( _secHelper . IsWindowAlive ( ) )
1627
+ {
1628
+ if ( DestroyWindowImpl ( ) )
1629
+ {
1630
+ ReleasePopupCapture ( ) ;
1631
+
1632
+ // Raise closed event after popup has actually closed
1633
+ OnClosed ( EventArgs . Empty ) ;
1634
+
1635
+ // When closing, clear the placement target registration
1636
+ UpdatePlacementTargetRegistration ( PlacementTarget , null ) ;
1637
+ }
1616
1638
}
1617
1639
}
1618
1640
0 commit comments