- 
                Notifications
    You must be signed in to change notification settings 
- Fork 416
Description
Description:
When dragging items from the application and dropping them outside (e.g., onto Explorer or browser), the DragDropPreview remains visible on screen. This appears to be caused by missing cleanup in external drop scenarios.
During external drag-drop operations, multiple exceptions are thrown (COMException and NotImplementedException), which might be interrupting the normal cleanup flow. These exceptions appear to be silently caught somewhere in the drag-drop operation but are preventing proper cleanup of visual elements.
While the issue can be worked around with a custom DragHandler that cleans up the preview in DragDropOperationFinished, the library should handle this scenario properly, including better exception handling during external drop operations.
Workaround:
public class CustomDragHandler : DefaultDragHandler
{
    public override void DragDropOperationFinished(DragDropEffects operationResult, IDragInfo dragInfo)
    {
        base.DragDropOperationFinished(operationResult, dragInfo);
        
        // Clean up DragDropPreview using reflection
        var dragDropType = typeof(GongSolutions.Wpf.DragDrop.DragDrop);
        var dragDropPreviewField = dragDropType.GetField("dragDropPreview", 
            BindingFlags.NonPublic | BindingFlags.Static);
        
        if (dragDropPreviewField != null)
        {
            var preview = dragDropPreviewField.GetValue(null);
            if (preview != null)
            {
                var isOpenProperty = preview.GetType().GetProperty("IsOpen");
                if (isOpenProperty != null)
                {
                    isOpenProperty.SetValue(preview, false);
                }
                dragDropPreviewField.SetValue(null, null);
            }
        }
    }
}