From 2293d8332eaa74f561a7e95a4b1646231509c691 Mon Sep 17 00:00:00 2001 From: Nikita Tsukanov Date: Fri, 9 Aug 2019 19:41:17 +0300 Subject: [PATCH] Explicitly drop pointer capture for DnD (not actually a fix for the underlying issue) --- samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs | 2 +- src/Avalonia.Controls/Platform/InProcessDragSource.cs | 3 ++- src/Avalonia.Input/DragDrop.cs | 4 ++-- src/Avalonia.Input/Platform/IPlatformDragSource.cs | 2 +- src/Windows/Avalonia.Win32/DragSource.cs | 5 +++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs b/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs index 718f21314e..0bf21c2820 100644 --- a/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs @@ -29,7 +29,7 @@ namespace ControlCatalog.Pages DataObject dragData = new DataObject(); dragData.Set(DataFormats.Text, $"You have dragged text {++DragCount} times"); - var result = await DragDrop.DoDragDrop(dragData, DragDropEffects.Copy); + var result = await DragDrop.DoDragDrop(e, dragData, DragDropEffects.Copy); switch(result) { case DragDropEffects.Copy: diff --git a/src/Avalonia.Controls/Platform/InProcessDragSource.cs b/src/Avalonia.Controls/Platform/InProcessDragSource.cs index 76f17332bf..85916bcdd0 100644 --- a/src/Avalonia.Controls/Platform/InProcessDragSource.cs +++ b/src/Avalonia.Controls/Platform/InProcessDragSource.cs @@ -33,9 +33,10 @@ namespace Avalonia.Platform _dragDrop = AvaloniaLocator.Current.GetService(); } - public async Task DoDragDrop(IDataObject data, DragDropEffects allowedEffects) + public async Task DoDragDrop(PointerEventArgs triggerEvent, IDataObject data, DragDropEffects allowedEffects) { Dispatcher.UIThread.VerifyAccess(); + triggerEvent.Pointer.Capture(null); if (_draggedData == null) { _draggedData = data; diff --git a/src/Avalonia.Input/DragDrop.cs b/src/Avalonia.Input/DragDrop.cs index c58b764b1d..d39659cee3 100644 --- a/src/Avalonia.Input/DragDrop.cs +++ b/src/Avalonia.Input/DragDrop.cs @@ -45,10 +45,10 @@ namespace Avalonia.Input /// Starts a dragging operation with the given and returns the applied drop effect from the target. /// /// - public static Task DoDragDrop(IDataObject data, DragDropEffects allowedEffects) + public static Task DoDragDrop(PointerEventArgs triggerEvent, IDataObject data, DragDropEffects allowedEffects) { var src = AvaloniaLocator.Current.GetService(); - return src?.DoDragDrop(data, allowedEffects) ?? Task.FromResult(DragDropEffects.None); + return src?.DoDragDrop(triggerEvent, data, allowedEffects) ?? Task.FromResult(DragDropEffects.None); } } } diff --git a/src/Avalonia.Input/Platform/IPlatformDragSource.cs b/src/Avalonia.Input/Platform/IPlatformDragSource.cs index bfe69f3a90..30d8ee5337 100644 --- a/src/Avalonia.Input/Platform/IPlatformDragSource.cs +++ b/src/Avalonia.Input/Platform/IPlatformDragSource.cs @@ -4,6 +4,6 @@ namespace Avalonia.Input.Platform { public interface IPlatformDragSource { - Task DoDragDrop(IDataObject data, DragDropEffects allowedEffects); + Task DoDragDrop(PointerEventArgs triggerEvent, IDataObject data, DragDropEffects allowedEffects); } } diff --git a/src/Windows/Avalonia.Win32/DragSource.cs b/src/Windows/Avalonia.Win32/DragSource.cs index a1bc5023a5..a8d74571a1 100644 --- a/src/Windows/Avalonia.Win32/DragSource.cs +++ b/src/Windows/Avalonia.Win32/DragSource.cs @@ -8,10 +8,11 @@ namespace Avalonia.Win32 { class DragSource : IPlatformDragSource { - public Task DoDragDrop(IDataObject data, DragDropEffects allowedEffects) + public Task DoDragDrop(PointerEventArgs triggerEvent, + IDataObject data, DragDropEffects allowedEffects) { Dispatcher.UIThread.VerifyAccess(); - + triggerEvent.Pointer.Capture(null); OleDragSource src = new OleDragSource(); DataObject dataObject = new DataObject(data); int allowed = (int)OleDropTarget.ConvertDropEffect(allowedEffects);