Repository navigation
Description
Current behavior 🐛
When a drag moves onto an AllowDrop element it wasn't over before, Uno raises only DragEnter for that move:
- The new element gets
DragEnter. Ancestors the drag was already over skip it, because they have already entered (UIElement.Pointers.cs:831-841). - No
DragOveris raised in the same pass (DropUITarget.cs:45-65). DropUITargetkeeps the accepted operation per drop target, so the new element's starts atNone(DropUITarget.cs:165-179).
So an ancestor that sets AcceptedOperation in DragOver doesn't run for that move. If the pointer is released before it moves again, the drop is rejected.
The visible case is a reorderable ListView whose item content sets AllowDrop="True". Drag an item onto the next item's content and release: DragItemsCompleted reports DropResult = None and nothing is reordered. The list's reorder handler is a DragOver handler, so it never sees that move.
Expected behavior 🎯
For one move, WinUI raises DragLeave on the elements the drag left, then DragEnter on the newly entered ones, then DragOver along the new path (CDragDropState::RaiseDragEnterEvents, InputServices.cpp:15015-15025).
The accepted operation is a single value for the whole drag. It is seeded into each event from the previous result, and reset only when the drag leaves the element that set it (DropOperationTarget.cpp:305-355, DragEventArgs.cpp:114-123).
This comes from reading the WinUI source. It wasn't run against WinUI.
How to reproduce it (as minimally and precisely as possible) 🔬
Runtime test on Skia Desktop. It uses UpdateLayoutOnUnloadedControl from Given_ListViewBase, which is what When_UpdateLayout_In_DragDropping uses.
[TestMethod]
[RunsOnUIThread]
public async Task When_Dropped_On_AllowDrop_Content_Of_Next_Item()
{
var list = new ListView { AllowDrop = true, CanDragItems = true, CanReorderItems = true };
for (var i = 0; i < 3; i++)
{
list.Items.Add(new UpdateLayoutOnUnloadedControl { Content = new TextBlock { AllowDrop = true, Height = 100, Text = i.ToString() } });
}
DataPackageOperation? result = null;
list.DragItemsCompleted += (_, e) => result = e.DropResult;
await UITestHelper.Load(list);
var injector = InputInjector.TryCreate() ?? throw new InvalidOperationException();
using var mouse = injector.GetMouse();
var bounds = list.GetAbsoluteBoundsRect();
mouse.MoveTo(bounds.GetCenter() with { Y = bounds.Y + 50 });
await WindowHelper.WaitForIdle();
mouse.Press();
await WindowHelper.WaitForIdle();
mouse.MoveTo(bounds.GetCenter() with { Y = bounds.Y + 100 }, 1);
await WindowHelper.WaitForIdle();
await UITestHelper.WaitForRender();
mouse.MoveTo(bounds.GetCenter() with { Y = bounds.Y + 250 }, 1);
await WindowHelper.WaitForIdle();
mouse.Release();
await WindowHelper.WaitForIdle();
Assert.AreEqual(DataPackageOperation.Move, result); // fails: None
}Events seen on the content TextBlocks:
| Step | Events |
|---|---|
| Move to y=100 | tb1.DragEnter, then tb1.DragOver, where the list sets Move |
| Move to y=250 | tb1.DragLeave, then tb2.DragEnter, and no DragOver |
| Release | tb2.DragLeave, no Drop, and DropResult = None |
Workaround 🛠️
Don't set AllowDrop on elements inside the items of a reorderable list.
Affected platforms 📱💻🖥️
Desktop (Windows). Verified on Win32; the code path is shared by every Skia head.
Uno.Sdk version (and other relevant versions) 📦
Uno master at faeb561, net11.0-desktop.
IDE version 🧑💻
Not IDE-related.
Anything else we need to know? 💬
- Drag events are not raised on elements below an AllowDrop ancestor (AllowDrop isn't inherited) #25275 is adjacent. With an inherited
AllowDrop, as in WinUI, every element under a list becomes a drop target, so this bug would hit every item-to-item move of a reorder. Fixing Drag events are not raised on elements below an AllowDrop ancestor (AllowDrop isn't inherited) #25275 on its own would make this one worse. When_UpdateLayout_In_DragDroppinginGiven_ListViewBasepasses on master because its release point is the top edge of the third item. There, the hit test lands on theScrollContentPresenterinstead of an item's content, so the list'sDragOverruns. Even that run reportsDropResult = None, although the items are reordered. Moving that point to y=210 or y=250 makes the test fail. feat(listview): Port ListViewItemPresenter and GridViewItemPresenter chrome #25389 changes the item template, so the same point lands on the content and the test fails there. That PR dropsAllowDropfrom the test's content and links this issue.- Separately, the same list rejects a drop at y=250 even when the content doesn't set
AllowDrop. The lastDragOveracceptsMove, but the drop then raisesDragLeaveinstead ofDrop. I haven't root-caused that one.
Activity
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
1 remaining item
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case
test(listview): Link the AllowDrop gap to #25754
test(listview): Keep the content AllowDrop drag case