Visitar URL original
fix(dragdrop): Load the drag visual by mikernet · Pull Request #25870 · unoplatform/uno · GitHub
Skip to content

fix(dragdrop): Load the drag visual - #25870

Open
mikernet wants to merge 1 commit into
unoplatform:masterfrom
mikernet:dev/mikernet/drag-view-loaded
Open

mikernet wants to merge 1 commit into
unoplatform:masterfrom
mikernet:dev/mikernet/drag-view-loaded

Conversation

@mikernet

@mikernet mikernet commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #25869

PR Type:

🐞 Bugfix

What changed? 🚀

The drag layer (DragRoot) now enters the live tree when InputManager.OpenDragAndDrop adds it, and leaves it before it's removed. The drag visual is loaded while it's shown, so it shows the dragged element again.

Before.

  • OpenDragAndDrop added the drag layer as a child of the visual tree's root element, which isn't active in the visual tree itself.
  • VisualTree.AddRoot enters each of its other roots explicitly (root.Enter(new EnterParams(isLive: true), 0)), but the drag layer was added without that. The drag visual was never live, and never loaded.
  • Since fix(imaging): Release a decoded image when nothing displays it #25124, an Image only subscribes to its source once it's loaded, as WinUI only decodes in the live tree. So the drag visual's Image showed nothing:
    • not the snapshot of the dragged element that Uno renders when the app sets no content in DragStarting, so no in-app drag showed the dragged element, only the caption tooltip;
    • not the content an app set with DragUI.SetContentFromBitmapImage or DragUIOverride.SetContentFromBitmapImage.

After.

  • OpenDragAndDrop enters the drag layer, live, right after adding it, as VisualTree.AddRoot does for the other roots. It skips that if the layer is already active, in case the root element is active.
  • When the last drag ends, it leaves the drag layer, live, before removing it, as WinUI's VisualTree::RemoveRoot does. The layer doesn't stay marked active after it's removed.
  • The drag layer and the drag visual get Loaded, then Unloaded when the drag ends, and the drag visual's image shows. The drag layer stays out of hit-testing (IsHitTestVisible is false).
  • Being loaded now also applies the drag visual's theme resources and visual states. I compared it in the light and dark application themes, before and after: the caption tooltip looks the same in each theme, and the image now shows.

Platforms: all, since the change is in shared code. Verified on Skia Desktop (Windows).

Tests: Given_DragView.When_Shown_Then_Loaded_And_Content_Image_Decodes shows a drag visual twice in a row through InputManager.OpenDragAndDrop, as the drag layer is removed after the first and added again for the second. Each time it has a BitmapImage (ms-appx:///Assets/square100.png) that nothing else shows. Each time, the test checks that:

  • the drag visual is loaded;
  • the image decodes (PixelWidth > 0);
  • the drag layer isn't hit-testable;
  • once the drag visual is closed, the drag visual is unloaded and the drag layer is no longer active.

On Skia Desktop (Windows), on master at 1f2fc30:

master This PR
When_Shown_Then_Loaded_And_Content_Image_Decodes fails: "The drag visual wasn't loaded (drag 1)." passes

I also ran Given_DragView, Given_Win32DragDrop, and the drag-and-drop tests of Given_UIElement, Given_ListViewBase and Given_TreeView: 25 tests, the new one included, all passing, after a build with the analyzers on.

Backport: not needed in servicing/6.8 unless #25124's Image change is backported there.

PR Checklist ✅

@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In-app drags no longer show the dragged element: the drag visual is never loaded

1 participant