فهرست منبع

Merge pull request #2323 from AvaloniaUI/fixes/2137-popuproot-parent

Make sure PopupRoot.Parent is a Popup.
Steven Kirk 6 سال پیش
والد
کامیت
dce5dab23d
1فایلهای تغییر یافته به همراه4 افزوده شده و 4 حذف شده
  1. 4 4
      src/Avalonia.Controls/Primitives/Popup.cs

+ 4 - 4
src/Avalonia.Controls/Primitives/Popup.cs

@@ -252,9 +252,9 @@ namespace Avalonia.Controls.Primitives
                 else
                 {
                     var parentPopuproot = _topLevel as PopupRoot;
-                    if (parentPopuproot != null && parentPopuproot.Parent != null)
+                    if (parentPopuproot?.Parent is Popup popup)
                     {
-                        ((Popup)(parentPopuproot.Parent)).Closed += ParentClosed;
+                        popup.Closed += ParentClosed;
                     }
                 }
                 _topLevel.AddHandler(PointerPressedEvent, PointerPressedOutside, RoutingStrategies.Tunnel);
@@ -293,9 +293,9 @@ namespace Avalonia.Controls.Primitives
                     else
                     {
                         var parentPopuproot = _topLevel as PopupRoot;
-                        if (parentPopuproot != null && parentPopuproot.Parent != null)
+                        if (parentPopuproot?.Parent is Popup popup)
                         {
-                            ((Popup)parentPopuproot.Parent).Closed -= ParentClosed;
+                            popup.Closed -= ParentClosed;
                         }
                     }
                     _nonClientListener?.Dispose();