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

moved document content null set after invoking the document closed ev… #212

Merged
merged 1 commit into from
Nov 30, 2020
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
31 changes: 17 additions & 14 deletions source/Components/AvalonDock/DockingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ This program is provided to you under the terms of the Microsoft Public

namespace AvalonDock
{
/// <inheritdoc cref="Control"/>
/// <inheritdoc cref="IOverlayWindowHost"/>
/// <summary>
/// The <see cref="DockingManager"/> is the custom control at the root of the visual tree.
/// This control is the core control of AvalonDock.
/// It contains core dependency properties, events, and methods to customize and
/// manage many aspects of the docking framework.
/// </summary>
/// <seealso cref="Control"/>
/// <seealso cref="IOverlayWindowHost"/>
[ContentProperty(nameof(Layout))]
/// <inheritdoc cref="Control"/>
/// <inheritdoc cref="IOverlayWindowHost"/>
/// <summary>
/// The <see cref="DockingManager"/> is the custom control at the root of the visual tree.
/// This control is the core control of AvalonDock.
/// It contains core dependency properties, events, and methods to customize and
/// manage many aspects of the docking framework.
/// </summary>
/// <seealso cref="Control"/>
/// <seealso cref="IOverlayWindowHost"/>
[ContentProperty(nameof(Layout))]
[TemplatePart(Name = "PART_AutoHideArea")]
public class DockingManager : Control, IOverlayWindowHost//, ILogicalChildrenContainer
{
Expand Down Expand Up @@ -1731,6 +1731,9 @@ internal void ExecuteCloseCommand(LayoutDocument document)
RemoveLogicalChild(uIElement);
DocumentClosed?.Invoke(this, new DocumentClosedEventArgs(document));

//get rid of the closed document content
document.Content = null;

int indexOfDocumentToSelect = indexOfDocumentToRemove - 1;

if (indexOfDocumentToSelect < 0)
Expand Down Expand Up @@ -2198,9 +2201,9 @@ private TLayoutType[] GetItemsToRemoveAfterReset<TLayoutType>(IEnumerable source
var itemsThatRemain = new HashSet<object>(source.Cast<object>(), ReferenceEqualityComparer.Default);
//Find the removed items that are not in the remaining collection
return Layout.Descendents()
.OfType<TLayoutType>()
.Where(x => !itemsThatRemain.Contains(x.Content))
.ToArray();
.OfType<TLayoutType>()
.Where(x => !itemsThatRemain.Contains(x.Content))
.ToArray();
}

private void DetachDocumentsSource(LayoutRoot layout, IEnumerable documentsSource)
Expand Down
3 changes: 1 addition & 2 deletions source/Components/AvalonDock/Layout/LayoutContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,7 @@ internal void CloseInternal()
}

parentAsContainer.RemoveChild(this);
root?.CollectGarbage();
this.Content = null;
root?.CollectGarbage();
OnClosed();
}

Expand Down