Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deserialized layout document close. #404

Merged
merged 1 commit into from
Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions source/Components/AvalonDock/DockingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,7 @@ private void DocumentsSourceElementsChanged(object sender, NotifyCollectionChang
var documentsToRemove = Layout.Descendents().OfType<LayoutDocument>().Where(d => e.OldItems.Contains(d.Content)).ToArray();
foreach (var documentToRemove in documentsToRemove)
{
documentToRemove.Content = null;
documentToRemove.Parent.RemoveChild(documentToRemove);
RemoveViewFromLogicalChild(documentToRemove);
}
Expand Down
14 changes: 14 additions & 0 deletions source/Components/AvalonDock/Layout/LayoutElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ public virtual void ConsoleDump(int tab)

#endregion Public Methods

#region Internal Methods

/// <summary>
/// When deserializing layout enclosing element parent is set later than this parent
/// We need to update it, otherwise when deleting this element <see cref="LayoutRoot.ElementRemoved" /> will no be called
/// </summary>
internal void FixCachedRootOnDeserialize()
{
if (_root == null)
_root = Root;
}

#endregion Internal Methods

#region protected methods

/// <summary>Provides derived classes an opportunity to handle execute code before to the <see cref="Parent"/> property changes.</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public LayoutSerializer(DockingManager manager)

protected virtual void FixupLayout(LayoutRoot layout)
{
foreach (var element in layout.Descendents().OfType<LayoutElement>()) element.FixCachedRootOnDeserialize();

//fix container panes
foreach (var lcToAttach in layout.Descendents().OfType<ILayoutPreviousContainer>().Where(lc => lc.PreviousContainerId != null))
{
Expand Down