Browse Source
Merge pull request #2827 from AvaloniaUI/dnd-hotfix
Hotfix for the DnD issue
scroll-measure
Nikita Tsukanov
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
9 additions and
7 deletions
-
samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs
-
src/Avalonia.Controls/Platform/InProcessDragSource.cs
-
src/Avalonia.Input/DragDrop.cs
-
src/Avalonia.Input/Platform/IPlatformDragSource.cs
-
src/Windows/Avalonia.Win32/DragSource.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: |
|
|
|
|
|
|
|
@ -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; |
|
|
|
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -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); |
|
|
|
|