"Not a function" when calling setDragImage with Drag & Drop #33158
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
question
Status: Resolved
I have a div that I want to give a custom draggable image (which can be an image or any element):
https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/setDragImage
I have a div I want to drag:
The callback is:
This JavaScript function is:
When calling the DataTransfer.setDragImage JavaScript function via JSRuntime via a @ondragstart Blazor callback, and passing a reference to the DragEventArgs I get an error:
Microsoft.JSInterop.JSException: event.dataTransfer.setDragImage is not a function
Apparantly, when the DragEventArgs is serialized / deserialized the function pointers are lost.
Please note that on Windows drag image elements with a width over 300px get a gradient overlay that is quite ugly depending on your underlying div and your personal feelings for aesthetics :-). Thus, for our solution we ended up with a completely custom implementation with a cloned ghost element that is following the mouse position. With a custom javascript event subscription we clear the dragImage:
Perhaps this information is useful when working on issue #18754.
Further technical details
The text was updated successfully, but these errors were encountered: