#261 Work around WinForms leak w/ cachedLayoutEventArgs

There is know issue with the WinForms layout engine where a deferred
layout can fail to clear the cached args when the layout is performed,
which leaves a reference to the since-disposed child pane on the
DockWindow.
This commit is contained in:
Ryan Rastedt
2014-12-07 11:20:18 -06:00
parent e661ea1cb4
commit 8a4ba8075f

View File

@@ -1313,5 +1313,33 @@ namespace WeifenLuo.WinFormsUI.Docking
}
#endregion
#region cachedLayoutArgs leak workaround
/// <summary>
/// There's a bug in the WinForms layout engine
/// that can result in a deferred layout to not
/// properly clear out the cached layout args after
/// the layout operation is performed.
/// Specifically, this bug is hit when the bounds of
/// the Pane change, initiating a layout on the parent
/// (DockWindow) which is where the bug hits.
/// To work around it, when a pane loses the DockWindow
/// as its parent, that parent DockWindow needs to
/// perform a layout to flush the cached args, if they exist.
/// </summary>
private DockWindow _lastParentWindow;
protected override void OnParentChanged(EventArgs e)
{
base.OnParentChanged(e);
var newParent = Parent as DockWindow;
if (newParent != _lastParentWindow)
{
if (_lastParentWindow != null)
_lastParentWindow.PerformLayout();
_lastParentWindow = newParent;
}
}
#endregion
}
}