fix(dock): strengthen drag payload validation and use event args in TabDroppedOutside

This commit is contained in:
2026-03-28 16:52:15 +09:00
parent 5ceb7c11ed
commit a409a93a10

View File

@@ -386,7 +386,8 @@ public sealed partial class DockLayout : Control
{
if (_dropTargetOverlay != null) _dropTargetOverlay.Visibility = Visibility.Collapsed;
if (!e.DataView.Properties.ContainsKey(DRAG_PROPERTY_DOCK_TAB) ||
if (!e.DataView.Properties.TryGetValue(DRAG_PROPERTY_DOCK_TAB, out var payload) ||
payload != _draggedItem ||
_draggedItem == null || _sourceNode == null || !(sender is FrameworkElement targetElement) || !(targetElement.Tag is DockPanelNode targetNode))
{
ClearDragOperationState();
@@ -424,13 +425,16 @@ public sealed partial class DockLayout : Control
{
try
{
if (_sourceNode != null && _draggedItem != null)
if (sender.Tag is DockPanelNode sourceNode && args.Item != null)
{
var result = TabTearOffService.TryTearOffTab(_sourceNode.Items, _draggedItem, _sourceNode);
// Validate that the item actually belongs to this source node before attempting tear-off
if (sourceNode.Items.Contains(args.Item))
{
var result = TabTearOffService.TryTearOffTab(sourceNode.Items, args.Item, sourceNode);
if (result.IsSuccess)
{
DockMutationEngine.CleanupEmptyNodes(_sourceNode);
DockMutationEngine.CleanupEmptyNodes(sourceNode);
}
else
{
@@ -438,6 +442,7 @@ public sealed partial class DockLayout : Control
}
}
}
}
finally
{
ClearDragOperationState();