fix: address code quality issues in DockContainer and DockPanel

- Throw ArgumentException in DockContainer.ReplaceChild if newChild is already in the container to avoid index shifting bugs.
- Add comment in DockPanel.CheckCleanup explaining the asymmetric root panel collapse behavior.
This commit is contained in:
2026-03-28 22:46:26 +09:00
parent e6d0529ef1
commit 0f0b36a932
2 changed files with 6 additions and 5 deletions

View File

@@ -102,12 +102,10 @@ public abstract class DockContainer : DockModule
// Detach newChild from its current owner if any // Detach newChild from its current owner if any
if (newChild.Owner == this) if (newChild.Owner == this)
{ {
newChild.Owner.RemoveChildInternal(newChild, false); throw new ArgumentException("newChild is already in this container", nameof(newChild));
} }
else
{
newChild.Owner?.RemoveChild(newChild); newChild.Owner?.RemoveChild(newChild);
}
// Remove oldChild without triggering cleanup // Remove oldChild without triggering cleanup
_isCleaningUp = true; _isCleaningUp = true;

View File

@@ -61,6 +61,9 @@ public class DockPanel : DockContainer
} }
else if (Root != null && Root.RootPanel == this) else if (Root != null && Root.RootPanel == this)
{ {
// We only collapse the root panel if the child is also a DockPanel
// because DockingLayout.RootPanel is strongly typed as DockPanel,
// so we can't assign a DockGroup to it directly.
if (child is DockPanel childPanel) if (child is DockPanel childPanel)
{ {
RemoveChildInternal(childPanel, false); RemoveChildInternal(childPanel, false);