-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to force WebView2 focus in WPF? #185
Comments
Great question. Do I understand correctly that you want to programmatically set focus to the WebView2? There's a Focus method on the control but it doesn't seem to work correctly and this seems like a bug. We'll look into this, thanks! |
Yep that's correct - thank you |
That's always been a problem with Web Browser controls in general. I think the way you can do this today is to force focus inside of the DOM by triggering some JavaScript code to focus on a control. |
I think two things have to be selected.
Doing 2 is easy enough.. but it doesn't even show as focused unless the control itself is focused. I tried everything I could think of to focus it without clicking, but I couldn't make it happen, but I'm assuming that it's possible to make available on some level. |
On the WPF side, calling It is possible to workaround (until it is properly fixed) this with an extension method:
This may not be 100% correct place to be setting focus, (subsequent calls to For example if you wanted to re-focus the most recently focused (web / HTML) control on a window when it is activated (title bar click or Alt+Tab into), you could:
(Note: the focus call must be queued up and not invoked synchronously because WPF will attempt to set focus on its own after the Activate event has completed). |
This should be fixed in SDK 0.9.538-prerelease. You should now be able to call .Focus() on the WebView2 control. Can you give that a try and see if this fixes you issue? If not, please reopen this issue and we'll take another look. Thanks! |
Fairly confident there is a related issue still present in at least the WinForms I have noticed that while the reported issue seems to be addressed in 0.9.538 and higher under normal circumstances, the Although this might be an uncommon circumstance, it represents a further issue with the inner Chromium window focus. |
@billybooth If you could open a new issue with your bug I'd appreciate it! |
I want to set up my window so that when I tab to it, it'll focus an input in the html.
This works fine from the html/js side, but I can't find a way in WebView2 to force the wpf control in focus.
Clicking it works, but obviously that isn't the solution.
The text was updated successfully, but these errors were encountered: