admin管理员组

文章数量:1355535

I am relatively new to .NET MAUI and am trying to implement a simple drag-and-drop function in a Razor component in a .NET MAUI Blazor hybrid app.

My problem: Only the dragstart event fires, while dragover and drop do not arrive. Also, I don't see any drag animation.

I noticed that .NET MAUI Blazor Hybrid does not enable interactive rendering by default, even though the events (drag, dragover, drop etc.) are defined in blazor.webview.js.

Here is a simple test code i've tried:

page "/dragdrop-test"

<div draggable="true" ondragstart="OnDragStart" style="background: lightblue; padding: 10px; width: 100px;">
    Drag me!
</div>
<div ondragover="OnDragOver" ondragover:preventDefault ondrop="OnDrop" style="border: 2px dashed red; padding: 20px; height: 100px;">
    Drop here!
</div>
<p>Log: logMessage</p>

code {
    private string logMessage = "Waiting...";
    private void OnDragStart(DragEventArgs args) => logMessage = "Drag started";
    private void OnDragOver(DragEventArgs args) => logMessage = "Drag over";
    private void OnDrop(DragEventArgs args) => logMessage = "Dropped";
}

In a Blazor WebAssembly app this works perfectly (all events + animation), but in MAUI Hybrid only dragstart.

My questions:

  1. Is the problem with the WebView2 under Windows, which does not process dragover and drop correctly or does not recognize drop targets?

  2. Or is it because blazor.webview.js intercepts the events but does not transfer them correctly to the .NET MAUI runtime?

  3. Is there a way to make this work in MAUI Hybrid without detours (e.g. complete JS interop)?

I currently have the WebView2 runtime and the events are clearly defined in blazor.webview.js. What could be the problem? Thanks for your help!

本文标签: cDrag and drop in NET MAUI Blazor Hybrid not working – WebView2 or interop issueStack Overflow