Browse Source

修复主窗口关闭时,副窗口未关闭

loki.wu 2 years ago
parent
commit
6b3c4b3015

+ 7 - 0
fis/MainWindow.axaml.cs

@@ -114,6 +114,13 @@ namespace fis
             }
 
             AppManager.ParentWindow = this;
+            Closed += MainWindow_Closed;
+        }
+
+        private void MainWindow_Closed(object? sender, EventArgs e)
+        {
+            var manager = AppManager.Get<ISecondaryScreenManager>();
+            manager.Dispose();
         }
     }
 

+ 2 - 0
fis/Managers/Interfaces/ISecondaryScreenManager.cs

@@ -25,5 +25,7 @@ namespace fis.Win.Dev.Managers.Interfaces
         /// <param name="windowType"></param>
         /// <returns></returns>
         SlaveWindow? GetWindowByType(WindowType windowType);
+
+
     }
 }

+ 5 - 1
fis/Managers/SecondaryScreenManager.cs

@@ -75,7 +75,11 @@ namespace fis.Win.Dev.Managers
 
         public void Dispose()
         {
-            
+            foreach (var w in windows.Keys) {
+                windows[w].ForceClose = true;
+                windows[w].Close();
+            }
+            windows.Clear();
         }
     }
 }

+ 10 - 5
fis/SlaveWindow.axaml.cs

@@ -24,6 +24,8 @@ namespace fis
         private string _host;
         private Dictionary<string, string> _parameters;
 
+        public bool ForceClose { get; set; } = false;
+
         public SlaveWindow()
         {
             ExtendClientAreaToDecorationsHint = true;
@@ -111,11 +113,14 @@ namespace fis
 
         private void SlaveWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
         {
-            e.Cancel = true;
-            WindowState = WindowState.Minimized;
-            ShowInTaskbar = false;
-            ShowActivated = false;
-            Hide();
+            if (!ForceClose)
+            {
+                e.Cancel = true;
+                WindowState = WindowState.Minimized;
+                ShowInTaskbar = false;
+                ShowActivated = false;
+                Hide();
+            }
         }
 
         private void InitializeComponent()