Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

GitHub Issue: closes #[issue_number]

PR Type:

  • 🐞 Bugfix

What is the current behavior? 🤔

Dragging image files from File Explorer into Uno Platform applications on Windows (Skia/WPF and Skia/Win32) shows no thumbnail near the cursor during the drag operation.

What is the new behavior? 🚀

External drag operations now display image thumbnails near the cursor on both Skia rendering backends. The implementation:

WPF Target Implementation

  • WpfDragDropExtension.OnHostDragEnter now creates a DragUI instance for external drags (previously null)
  • CreateDragUIForExternalDrag - Creates DragUI with thumbnail content
    • Fast path: Uses OS-provided bitmap if available (DataFormats.Bitmap)
    • Fallback: Loads first image file from drag data
    • Supports: .png, .jpg, .jpeg, .gif, .bmp, .tiff, .ico
  • LoadImageFromFile - Loads images with 96px thumbnail size, validates file existence
  • ConvertBitmapSourceToUnoBitmapImage - Converts WPF BitmapSource to Uno BitmapImage via PNG encoding with 8KB pre-allocated buffer

Win32 Target Implementation

  • Win32DragDropExtension.DragEnter now creates a DragUI instance for external drags (previously null)
  • CreateDragUIForExternalDrag - Creates DragUI with thumbnail content from Win32 formats
    • Retrieves data directly from IDataObject with proper STGMEDIUM lifecycle management
    • Supports CF_DIB (Device Independent Bitmap) format
    • Supports CF_HDROP (file drop) format with image file detection
    • Properly releases STGMEDIUM resources using try-finally blocks
  • ExtractFilePathsFromHDrop - Extracts file paths from Win32 HDROP handle using DragQueryFile API
  • ConvertDibToUnoBitmapImage - Converts Win32 DIB format to Uno BitmapImage
  • LoadImageFromFile - Loads images from file system with validation
  • IsImageFile - Detects image files by extension

Error Handling (Both Targets)

  • Catches specific exceptions: IOException, UnauthorizedAccessException, NotSupportedException, UriFormatException
  • Graceful degradation: Returns DragUI without content on errors
  • Debug logging for troubleshooting

Resource Management (Win32)

  • STGMEDIUM properly acquired and released for each data format
  • Try-finally blocks ensure cleanup even if image conversion fails
  • Independent data retrieval eliminates dependency on indexed lists

PR Checklist ✅

  • 📝 Commits follow Conventional Commits specification
  • 🧪 Runtime/UI tests added (manual testing required - DragDrop_Files sample)
  • 📚 Docs updated (not applicable - internal fix)
  • 🖼️ Screenshot validation (requires manual testing)
  • ❗ Contains NO breaking changes

Other information ℹ️

Thumbnails show by default (CoreDragUIOverride.IsContentVisible = true). Applications can hide them via DragUIOverride in drag event handlers.

This fix applies to both WPF and Win32 Skia rendering backends on Windows Desktop, ensuring consistent drag-and-drop visual feedback across both implementations.

Win32 Implementation Note: The initial implementation had an indexing bug where it assumed mediumsToDispose aligned with formatEtcList, but mediumsToDispose only contains mediums for formats actually retrieved by ReadContentIntoPackage. This was fixed by retrieving data directly from the IDataObject when creating the DragUI.

  • Fixes unoplatform/kahua-private#372
Original prompt

This section details on the original issue you should resolve

<issue_title>When Dragging and Dropping an Image into Kahua, we no longer see the thumbnail around the cursor</issue_title>
<issue_description>### Current behavior 🐛

When dragging and dropping an image file into Kahua, we do not see the thumbnail for the image near the cursor

2025-10-29_11-32-38.mp4

Expected behavior 🎯

When dragging and dropping an image file into kahua, the thumbnail displays near the cursor prior to drop

2025-10-29_11-29-51.mp4

How to reproduce it (as minimally and precisely as possible) 🔬

Repro Steps:

  1. Log in as any user and open File Manager
  2. Drag an image from file explorer onto the log view

Workaround 🛠️

None

Renderer 🎨

  • Skia
  • Native

Affected platforms 📱💻🖥️

Desktop (Windows)

Uno.Sdk version (and other relevant versions) 📦

.59 devbits

IDE version 🧑‍💻

No response

Anything else we need to know? 💬

No response</issue_description>

Comments on the Issue (you are @copilot in this section)

@Jen-Uno @ChaseKopp6 Nov 1 or 7th?
  • Fixes unoplatform/kahua-private#372

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@CLAassistant
Copy link

CLAassistant commented Nov 6, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ MartinZikmund
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Fix missing thumbnail on image drag and drop in Kahua fix: Add DragUI support for external drag operations on Windows (Skia/WPF) Nov 6, 2025
Copilot AI requested a review from MartinZikmund November 6, 2025 13:04
Copilot finished work on behalf of MartinZikmund November 6, 2025 13:04
@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21759/wasm-skia-net9/index.html

@unodevops
Copy link
Contributor

⚠️⚠️ The build 181251 has failed on Uno.UI - CI.

@MartinZikmund
Copy link
Member

@copilot please implement this for Win32 target as well

Copy link
Contributor Author

Copilot AI commented Nov 7, 2025

@copilot please implement this for Win32 target as well

Implemented in commit efe66dc. The Win32 target now has the same DragUI support for external drag operations, including:

  • CF_DIB bitmap format support with conversion to Uno BitmapImage
  • CF_HDROP file drop support with image file detection
  • Helper methods for extracting file paths and loading images
  • Consistent error handling and debug logging

The implementation follows the same pattern as the WPF target but uses Win32 APIs to extract bitmap data from HGLOBAL handles.

Copilot AI changed the title fix: Add DragUI support for external drag operations on Windows (Skia/WPF) fix: Add DragUI support for external drag operations on Windows (Skia/WPF and Skia/Win32) Nov 7, 2025
Copilot finished work on behalf of MartinZikmund November 7, 2025 09:49
@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21759/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21759/wasm-skia-net9/index.html

@MartinZikmund
Copy link
Member

@copilot It does not seem to work on Win32, CreateDragUIForExternalDrag hdropFormatIndex becomes 6, but the following if then fails because mediumsToDispose.Count is 1

Copy link
Contributor Author

Copilot AI commented Nov 7, 2025

@copilot It does not seem to work on Win32, CreateDragUIForExternalDrag hdropFormatIndex becomes 6, but the following if then fails because mediumsToDispose.Count is 1

Fixed in commit c705ac5. The issue was that mediumsToDispose only contains mediums for formats actually retrieved by ReadContentIntoPackage (filtered list), while formatEtcList contains all formats. The indexing logic was incorrect.

The fix retrieves data directly from the IDataObject when creating DragUI, properly managing STGMEDIUM lifecycle with try-finally blocks for cleanup. This eliminates the dependency on the indexed medium list.

Copilot finished work on behalf of MartinZikmund November 7, 2025 11:40
@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21759/docs/index.html

@unodevops
Copy link
Contributor

⚠️⚠️ The build 181478 has failed on Uno.UI - CI.

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21759/wasm-skia-net9/index.html

@github-actions github-actions bot added area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/wpf 🪟 Categorizes an issue or PR as relevant to WPF labels Nov 7, 2025
@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-21759/docs/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-21759/wasm-skia-net9/index.html

@unodevops
Copy link
Contributor

⚠️⚠️ The build 181506 has failed on Uno.UI - CI.

@MartinZikmund
Copy link
Member

@Mergifyio backport release/stable/6.4

@mergify
Copy link
Contributor

mergify bot commented Nov 7, 2025

backport release/stable/6.4

🟠 Waiting for conditions to match

  • merged [📌 backport requirement]

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

Labels

area/skia ✏️ Categorizes an issue or PR as relevant to Skia platform/wpf 🪟 Categorizes an issue or PR as relevant to WPF

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants