فهرست منبع

Fixed cancelling subpanels

Kenric Nugteren 7 ماه پیش
والد
کامیت
126e8093ba
1فایلهای تغییر یافته به همراه24 افزوده شده و 6 حذف شده
  1. 24 6
      inabox.wpf/Panel/IPanel.cs

+ 24 - 6
inabox.wpf/Panel/IPanel.cs

@@ -257,6 +257,14 @@ public static class IPanelHostExtensions
     }
 }
 
+/// <summary>
+/// Implement this interface to cause a class to act as a host of <see cref="ISubPanel"/>. Then, you can use the extension functions
+/// <see cref="ISubPanelHostExtensions.ShutdownSubPanels(ISubPanelHost, CancelEventArgs?)"/> and
+/// <see cref="ISubPanelHostExtensions.AddSubPanel(ISubPanelHost, ISubPanel)"/> to interact with it.
+/// </summary>
+/// <remarks>
+/// If you mark an <see cref="IPanel{T}"/> as an <see cref="ISubPanelHost"/>, then the shutdown method is called automatically by <see cref="IPanelHost"/>.
+/// </remarks>
 public interface ISubPanelHost
 {
     List<ISubPanel> SubPanels { get; }
@@ -278,14 +286,24 @@ public static class ISubPanelHostExtensions
         {
             panels = host.SubPanels.ToArray();
             host.SubPanels.Clear();
-        }
 
-        foreach(var panel in panels)
-        {
-            panel.Shutdown(cancel);
-            if (cancel?.Cancel == true)
+            var isCancelled = false;
+
+            foreach(var panel in panels)
             {
-                return;
+                if (isCancelled)
+                {
+                    host.SubPanels.Add(panel);
+                }
+                else
+                {
+                    panel.Shutdown(cancel);
+                    if (cancel?.Cancel == true)
+                    {
+                        isCancelled = true;
+                        host.SubPanels.Add(panel);
+                    }
+                }
             }
         }
     }