Skip to content

Commit

Permalink
fix: fire Dragover events to accompany DragEnter and Drop
Browse files Browse the repository at this point in the history
  • Loading branch information
ramezgerges committed Apr 9, 2024
1 parent 05f6502 commit d8051cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/Uno.UI/UI/Xaml/DragDrop/DragEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ internal DragEventArgs(
DragUIOverride = uiOverride;
}

internal DragEventArgs(DragEventArgs args) : this((UIElement)args.OriginalSource, args._info, args.DragUIOverride)
{
AcceptedOperation = args.AcceptedOperation;
}

#region Readonly properties that gives context to the handler
public bool Handled { get; set; }

Expand Down
22 changes: 17 additions & 5 deletions src/Uno.UI/UI/Xaml/UIElement.Pointers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -792,13 +792,18 @@ private protected virtual void PrepareShare(DataPackage data)

internal void RaiseDragEnterOrOver(global::Microsoft.UI.Xaml.DragEventArgs args)
{
var evt = IsDragOver(args.SourceId)
? DragOverEvent
: DragEnterEvent;
var wasDragOver = IsDragOver(args.SourceId);

(_draggingOver ??= new HashSet<long>()).Add(args.SourceId);

SafeRaiseEvent(evt, args);
if (!wasDragOver)
{
var args2 = new DragEventArgs(args);
SafeRaiseEvent(DragEnterEvent, args);
args.AcceptedOperation = args2.AcceptedOperation;
}

SafeRaiseEvent(DragOverEvent, args);
}

internal void RaiseDragLeave(global::Microsoft.UI.Xaml.DragEventArgs args, UIElement upTo = null)
Expand All @@ -813,7 +818,14 @@ internal void RaiseDrop(global::Microsoft.UI.Xaml.DragEventArgs args)
{
if (_draggingOver?.Remove(args.SourceId) ?? false)
{
SafeRaiseEvent(DropEvent, args);
var args2 = new DragEventArgs(args);
SafeRaiseEvent(DragOverEvent, args2);
args.AcceptedOperation = args2.AcceptedOperation;
// On WinUI, if the final DragOver event sets AcceptedOperation to None, the DropEvent won't fire
if (args.AcceptedOperation is not DataPackageOperation.None)
{
SafeRaiseEvent(DropEvent, args);
}
}
}
#endregion
Expand Down

0 comments on commit d8051cc

Please sign in to comment.