From 38b2d500added632714c7bf8b4ed35dd8b69137d Mon Sep 17 00:00:00 2001 From: pkindruk Date: Fri, 2 Dec 2022 22:13:03 +0300 Subject: [PATCH] Fix deserialized layout document close. --- source/Components/AvalonDock/DockingManager.cs | 1 + .../Components/AvalonDock/Layout/LayoutElement.cs | 14 ++++++++++++++ .../Layout/Serialization/LayoutSerializer.cs | 2 ++ 3 files changed, 17 insertions(+) diff --git a/source/Components/AvalonDock/DockingManager.cs b/source/Components/AvalonDock/DockingManager.cs index 762917bc..2592d712 100644 --- a/source/Components/AvalonDock/DockingManager.cs +++ b/source/Components/AvalonDock/DockingManager.cs @@ -2230,6 +2230,7 @@ private void DocumentsSourceElementsChanged(object sender, NotifyCollectionChang var documentsToRemove = Layout.Descendents().OfType().Where(d => e.OldItems.Contains(d.Content)).ToArray(); foreach (var documentToRemove in documentsToRemove) { + documentToRemove.Content = null; documentToRemove.Parent.RemoveChild(documentToRemove); RemoveViewFromLogicalChild(documentToRemove); } diff --git a/source/Components/AvalonDock/Layout/LayoutElement.cs b/source/Components/AvalonDock/Layout/LayoutElement.cs index 29da33f2..d49e1f6a 100644 --- a/source/Components/AvalonDock/Layout/LayoutElement.cs +++ b/source/Components/AvalonDock/Layout/LayoutElement.cs @@ -109,6 +109,20 @@ public virtual void ConsoleDump(int tab) #endregion Public Methods + #region Internal Methods + + /// + /// When deserializing layout enclosing element parent is set later than this parent + /// We need to update it, otherwise when deleting this element will no be called + /// + internal void FixCachedRootOnDeserialize() + { + if (_root == null) + _root = Root; + } + + #endregion Internal Methods + #region protected methods /// Provides derived classes an opportunity to handle execute code before to the property changes. diff --git a/source/Components/AvalonDock/Layout/Serialization/LayoutSerializer.cs b/source/Components/AvalonDock/Layout/Serialization/LayoutSerializer.cs index 7244045f..8c133bb5 100644 --- a/source/Components/AvalonDock/Layout/Serialization/LayoutSerializer.cs +++ b/source/Components/AvalonDock/Layout/Serialization/LayoutSerializer.cs @@ -60,6 +60,8 @@ public LayoutSerializer(DockingManager manager) protected virtual void FixupLayout(LayoutRoot layout) { + foreach (var element in layout.Descendents().OfType()) element.FixCachedRootOnDeserialize(); + //fix container panes foreach (var lcToAttach in layout.Descendents().OfType().Where(lc => lc.PreviousContainerId != null)) {