You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There have been two issues found while using the drag-and-drop feature with TreeViewItem:
'DragOver' and 'Drop' Events Not Triggered
When dragging an element from a different component onto a TreeViewItem, the DragOver and Drop events are not triggered if the item is hovered over or dropped directly without interacting with other items first. However, if multiple items are hovered over sequentially, the events fire as expected, starting from the second item onward.
UPDATE: The proposed workaround for this issue was to use the DragEnter event instead, which does work. However, I still find it inconsistent that two similar events get triggered differently. Moreover, DragOver is the only event handler that is proposed to accept the request in this article, which seems a bit confusing: https://learn.microsoft.com/en-us/windows/apps/design/input/drag-and-drop
Stuck 'PointerOver' Visual State
Dragging an element from a different component and dropping it onto a TreeViewItem causes the item to remain stuck in the PointerOver visual state forever, unless it gets touched with another dragged item again.
The workaround for the 2nd issue by using VisualStateManager.GoToStatehas issues as well. Although it can force the visual state to revert to Normal, this only works if the state was set after the pointer left the item. If it was set while the pointer was on the item, the item will revert to its wrong PointerOver state again as soon as the pointer is out. To fully resolve the issue, the VisualStateManager.GoToState has to be put inside the PointerExit event handler.
@datskiy I cloned your solution and was able to replicate your behavior, however, to get the copy to show up the way you are expecting, you need to set the accepted operation first on DragEnter as well as DragOver.
@Skittles2519 Thank you for your response! It does resolve the issue, but it also got me thinking more about the matter. The thing is, in my tests the events were firing correctly on other controls like ListView or just a StackPanel, even without handling the DragEnter event. I tried re-attaching the drag-and-drop event to the TreeView itself, and it partially resolved this particular issue, but the events now come from TreeView and not TreeViewItem.
Anyway, DragEnter does help to resolve the 1st issue, but I still find it inconsistent that two similar events get triggered differently. Moreover, DragOver is the only event handler that is proposed to accept the operation request in this article, which seems a bit confusing: https://learn.microsoft.com/en-us/windows/apps/design/input/drag-and-drop
That said, the target element still gets stuck in the PointerOver state after dropping, so the 2nd issue is still relevant.
Describe the bug
There have been two issues found while using the drag-and-drop feature with
TreeViewItem
:'DragOver' and 'Drop' Events Not Triggered
When dragging an element from a different component onto a
TreeViewItem
, theDragOver
andDrop
events are not triggered if the item is hovered over or dropped directly without interacting with other items first. However, if multiple items are hovered over sequentially, the events fire as expected, starting from the second item onward.UPDATE: The proposed workaround for this issue was to use the
DragEnter
event instead, which does work. However, I still find it inconsistent that two similar events get triggered differently. Moreover,DragOver
is the only event handler that is proposed to accept the request in this article, which seems a bit confusing: https://learn.microsoft.com/en-us/windows/apps/design/input/drag-and-dropStuck 'PointerOver' Visual State
Dragging an element from a different component and dropping it onto a
TreeViewItem
causes the item to remain stuck in thePointerOver
visual state forever, unless it gets touched with another dragged item again.The workaround for the 2nd issue by using
VisualStateManager.GoToState
has issues as well. Although it can force the visual state to revert toNormal
, this only works if the state was set after the pointer left the item. If it was set while the pointer was on the item, the item will revert to its wrongPointerOver
state again as soon as the pointer is out. To fully resolve the issue, theVisualStateManager.GoToState
has to be put inside thePointerExit
event handler.Steps to reproduce the bug
TreeViewItem
, without touching any other items.DragOver
andDrop
events are not triggered unless you hover over multiple items first. The drop will fire theDragLeave
event only.TreeViewItem
and observe that the chosenTreeViewItem
item gets stuck in thePointerOver
state.Expected behavior
DragOver
andDrop
events should consistently trigger when interacting withTreeViewItem
.TreeViewItem
should properly transition out of thePointerOver
visual state after a drop operation.Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003
Windows version
Windows 11 (24H2): Build 26100
Additional context
The
VisualStateManager
workaround mentioned above might help with the stuckPointerOver
state, but only when the pointer exited the item.Source code: https://github.com/datskiy/TreeViewItemDropIssue
The text was updated successfully, but these errors were encountered: