Browse Source

Explicitly drop pointer capture for DnD (not actually a fix for the underlying issue)

pull/2827/head
Nikita Tsukanov 7 years ago
parent
commit
2293d8332e
  1. 2
      samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs
  2. 3
      src/Avalonia.Controls/Platform/InProcessDragSource.cs
  3. 4
      src/Avalonia.Input/DragDrop.cs
  4. 2
      src/Avalonia.Input/Platform/IPlatformDragSource.cs
  5. 5
      src/Windows/Avalonia.Win32/DragSource.cs

2
samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs

@ -29,7 +29,7 @@ namespace ControlCatalog.Pages
DataObject dragData = new DataObject(); DataObject dragData = new DataObject();
dragData.Set(DataFormats.Text, $"You have dragged text {++DragCount} times"); 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) switch(result)
{ {
case DragDropEffects.Copy: case DragDropEffects.Copy:

3
src/Avalonia.Controls/Platform/InProcessDragSource.cs

@ -33,9 +33,10 @@ namespace Avalonia.Platform
_dragDrop = AvaloniaLocator.Current.GetService<IDragDropDevice>(); _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(); Dispatcher.UIThread.VerifyAccess();
triggerEvent.Pointer.Capture(null);
if (_draggedData == null) if (_draggedData == null)
{ {
_draggedData = data; _draggedData = data;

4
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. /// Starts a dragging operation with the given <see cref="IDataObject"/> and returns the applied drop effect from the target.
/// <seealso cref="DataObject"/> /// <seealso cref="DataObject"/>
/// </summary> /// </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>(); 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);
} }
} }
} }

2
src/Avalonia.Input/Platform/IPlatformDragSource.cs

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

5
src/Windows/Avalonia.Win32/DragSource.cs

@ -8,10 +8,11 @@ namespace Avalonia.Win32
{ {
class DragSource : IPlatformDragSource class DragSource : IPlatformDragSource
{ {
public Task<DragDropEffects> DoDragDrop(IDataObject data, DragDropEffects allowedEffects) public Task<DragDropEffects> DoDragDrop(PointerEventArgs triggerEvent,
IDataObject data, DragDropEffects allowedEffects)
{ {
Dispatcher.UIThread.VerifyAccess(); Dispatcher.UIThread.VerifyAccess();
triggerEvent.Pointer.Capture(null);
OleDragSource src = new OleDragSource(); OleDragSource src = new OleDragSource();
DataObject dataObject = new DataObject(data); DataObject dataObject = new DataObject(data);
int allowed = (int)OleDropTarget.ConvertDropEffect(allowedEffects); int allowed = (int)OleDropTarget.ConvertDropEffect(allowedEffects);

Loading…
Cancel
Save