浏览代码

Merge pull request #2827 from AvaloniaUI/dnd-hotfix

Hotfix for the DnD issue
Nikita Tsukanov 6 年之前
父节点
当前提交
212eec6be7

+ 1 - 1
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:

+ 2 - 1
src/Avalonia.Controls/Platform/InProcessDragSource.cs

@@ -33,9 +33,10 @@ namespace Avalonia.Platform
             _dragDrop = AvaloniaLocator.Current.GetService<IDragDropDevice>();
         }
 
-        public async Task<DragDropEffects> DoDragDrop(IDataObject data, DragDropEffects allowedEffects)
+        public async Task<DragDropEffects> DoDragDrop(PointerEventArgs triggerEvent, IDataObject data, DragDropEffects allowedEffects)
         {
             Dispatcher.UIThread.VerifyAccess();
+            triggerEvent.Pointer.Capture(null);
             if (_draggedData == null)
             {
                 _draggedData = data;

+ 2 - 2
src/Avalonia.Input/DragDrop.cs

@@ -45,10 +45,10 @@ namespace Avalonia.Input
         /// Starts a dragging operation with the given <see cref="IDataObject"/> and returns the applied drop effect from the target.
         /// <seealso cref="DataObject"/>
         /// </summary>
-        public static Task<DragDropEffects> DoDragDrop(IDataObject data, DragDropEffects allowedEffects)
+        public static Task<DragDropEffects> DoDragDrop(PointerEventArgs triggerEvent, IDataObject data, DragDropEffects allowedEffects)
         {
             var src = AvaloniaLocator.Current.GetService<IPlatformDragSource>();
-            return src?.DoDragDrop(data, allowedEffects) ?? Task.FromResult(DragDropEffects.None);
+            return src?.DoDragDrop(triggerEvent, data, allowedEffects) ?? Task.FromResult(DragDropEffects.None);
         }
     }
 }

+ 1 - 1
src/Avalonia.Input/Platform/IPlatformDragSource.cs

@@ -4,6 +4,6 @@ namespace Avalonia.Input.Platform
 {
     public interface IPlatformDragSource
     {
-        Task<DragDropEffects> DoDragDrop(IDataObject data, DragDropEffects allowedEffects);
+        Task<DragDropEffects> DoDragDrop(PointerEventArgs triggerEvent, IDataObject data, DragDropEffects allowedEffects);
     }
 }

+ 3 - 2
src/Windows/Avalonia.Win32/DragSource.cs

@@ -8,10 +8,11 @@ namespace Avalonia.Win32
 {
     class DragSource : IPlatformDragSource
     {
-        public Task<DragDropEffects> DoDragDrop(IDataObject data, DragDropEffects allowedEffects)
+        public Task<DragDropEffects> 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);