WebView2 Drop Support from OS Files #3917
Replies: 2 comments
-
That's a Chromium issue in general. When you drop a file onto the browser it assumes you want to open the document in the browser. The way you can deal with this is that you can capture the browser before navigation event and pick up the document file name from there and then forward that to your browser script code similar to the way you'd handle a drop operation. I've looked into this a lot for Markdown Monster and have not found another way to to do this. What I do in MM is capture the navigation event and determine it's a dropped file (in my case any file but my preview file) and then capture the file name. Then inject the file reference into my document at the current cursor position using browser scripting (ExecuteScriptAysnc() into my browser app code). Works fine - the main issue is that you don't get precise positioning. You basically have to use existing cursor or caret position or potentially try to capture the mouse position before you process the file inside of browser code through slight delays and mouse capture. FWIW, dragging files from other browser windows properly works with drag events. It's mainly OS file dropping that does not work. |
Beta Was this translation helpful? Give feedback.
-
Related: #278 |
Beta Was this translation helpful? Give feedback.
-
In my application I have various ways to capture drag and drop operations onto the WebView. It looks like drag and drop from application specific content using the Data object works great. I can capture the
onDrop
event in the browser and that seems to work just fine.However, when I drag files from Explorer onto the WebView it doesn't work. I see a
Copy
icon show but when I drop any file on the WebView it just opens in the Windows default viewer for the file (ie. html in browser, images in image viewer etc.)I can't seem to capture the drop operation with:
Clearly the WebView knows something is being dragged over it as I see the
copy
icon, but unlike the WPF content (which shows a different cursor altogether even though I push Windows style file data into my Drag Data) I can't seem to capture the file.In the old WebBrowser control I had to detect navigation events to make this work, but it looks like that doesn't work with the webview either.
Any ideas how to detect what's being dropped?
Beta Was this translation helpful? Give feedback.
All reactions