diff --git a/src/Editor/Ghost.Editor/View/Controls/DockLayout.Rendering.cs b/src/Editor/Ghost.Editor/View/Controls/DockLayout.Rendering.cs index 7498198..bb1012d 100644 --- a/src/Editor/Ghost.Editor/View/Controls/DockLayout.Rendering.cs +++ b/src/Editor/Ghost.Editor/View/Controls/DockLayout.Rendering.cs @@ -110,50 +110,52 @@ public sealed partial class DockLayout { if (_isSyncingSizes) return; - bool isHorizontal = groupNode.Orientation == Orientation.Horizontal; - bool changed = false; - - if (isHorizontal) + try { - for (int i = 0; i < groupNode.Children.Count; i++) + bool isHorizontal = groupNode.Orientation == Orientation.Horizontal; + bool changed = false; + + if (isHorizontal) { - if (i < groupNode.Sizes.Count && i * 2 < grid.ColumnDefinitions.Count) + for (int i = 0; i < groupNode.Children.Count; i++) { - var newWidth = grid.ColumnDefinitions[i * 2].Width; - if (!groupNode.Sizes[i].Equals(newWidth)) + if (i < groupNode.Sizes.Count && i * 2 < grid.ColumnDefinitions.Count) { - // Only sync if it's a star or pixel value (not Auto) - if (newWidth.IsStar || newWidth.IsAbsolute) + var newWidth = grid.ColumnDefinitions[i * 2].Width; + if (!groupNode.Sizes[i].Equals(newWidth)) { - _isSyncingSizes = true; - groupNode.Sizes[i] = newWidth; - changed = true; + // Only sync if it's a star or pixel value (not Auto) + if (newWidth.IsStar || newWidth.IsAbsolute) + { + _isSyncingSizes = true; + groupNode.Sizes[i] = newWidth; + changed = true; + } + } + } + } + } + else + { + for (int i = 0; i < groupNode.Children.Count; i++) + { + if (i < groupNode.Sizes.Count && i * 2 < grid.RowDefinitions.Count) + { + var newHeight = grid.RowDefinitions[i * 2].Height; + if (!groupNode.Sizes[i].Equals(newHeight)) + { + if (newHeight.IsStar || newHeight.IsAbsolute) + { + _isSyncingSizes = true; + groupNode.Sizes[i] = newHeight; + changed = true; + } } } } } } - else - { - for (int i = 0; i < groupNode.Children.Count; i++) - { - if (i < groupNode.Sizes.Count && i * 2 < grid.RowDefinitions.Count) - { - var newHeight = grid.RowDefinitions[i * 2].Height; - if (!groupNode.Sizes[i].Equals(newHeight)) - { - if (newHeight.IsStar || newHeight.IsAbsolute) - { - _isSyncingSizes = true; - groupNode.Sizes[i] = newHeight; - changed = true; - } - } - } - } - } - - if (changed) + finally { _isSyncingSizes = false; } diff --git a/src/Editor/Ghost.Editor/View/Windows/EngineEditorWindow.xaml.cs b/src/Editor/Ghost.Editor/View/Windows/EngineEditorWindow.xaml.cs index b9835ab..c6ce59d 100644 --- a/src/Editor/Ghost.Editor/View/Windows/EngineEditorWindow.xaml.cs +++ b/src/Editor/Ghost.Editor/View/Windows/EngineEditorWindow.xaml.cs @@ -42,6 +42,13 @@ internal sealed partial class EngineEditorWindow : WindowEx this.CenterOnScreen(); InitializeDockLayout(); + + this.Unloaded += OnUnloaded; + } + + private void OnUnloaded(object sender, RoutedEventArgs e) + { + PART_DockLayout.TabTornOff -= OnTabTornOff; } private void InitializeDockLayout() @@ -68,7 +75,12 @@ internal sealed partial class EngineEditorWindow : WindowEx root.AddChild(rightGroup); PART_DockLayout.Root = root; - PART_DockLayout.TabTornOff += (s, e) => App.CreateAndShowDockWindow(e.TabContent); + PART_DockLayout.TabTornOff += OnTabTornOff; + } + + private void OnTabTornOff(object? sender, TabTornOffEventArgs e) + { + App.CreateAndShowDockWindow(e.TabContent); } private void MainGrid_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)