-
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
Form not displayed in foreground #334
Comments
Thanks! I've filed a bug and we will follow up. |
@fvanheeswijk, To get the form to display on top, when the button is clicked with the mouse, give the following a try. I've tested it and it seems to work. Replace the Handler class code with the following:
*Note: You must include |
Here's another version of the Handler class that also works when the button is clicked with the mouse.
*Note: This code combines your code with the code from the article: Execution vs SynchronizationContext |
Hello, I've just had time to test your code, but unfortunately it doesn't resolve our issue. |
I also want to emphasize that this issue is urgent for us, it looks like the WebView2 webbrowser is heading towards a stable state yet we cannot use it yet due to at least this issue. And we are seeing an increased influx on issues on the old webbowser control, so we need to replace it. |
@fvanheeswijk We'll try and take a deeper look shortly. It looks like it's probably related to window activation or focus due to the threading. If I don't try and open the window in a new thread it correctly shows up in the foreground for me. Until we have a fix, how important is the multi-threading for your scenario? |
Okay, thank you for taking a deeper look into this! |
Has there been any news yet? We are still running into this issue unfortunately, while this issue persists and no workaround is available we cannot continue with the WebView2 adaptation. |
I've got some extra information that may help with this problem. Currently we are running the EO (Essential Objects) webbrowser which is also Chromium-based just like the WebView2, when implementing it we ran into a similar issue with windows not appearing on the foreground but instead on the background. Back then the developers have fixed it by calling AllowSetForegroundWindow from the webbrowser process such that it would allow the calling application (our executable) to put windows on top of windows from the webbrowser process. This may also be the case here and hopefully this will be of help to you. Because I don't think there's a reason why the program that includes the webbrowser may not be on top of said webbrowser. I believe normally there is a link between threads and processes that would grant such permission but in the case of creating a new thread that link is lost so permission needs to be given on a global level. Also, if it is possible to write our code in the browser process executable somewhere it could be of help as well, do you know any possibility regarding that? |
Thanks for the extra info, I've added it to the bug. We haven't been able to take a look at this particular bug yet, but I've just bumped the priority so hopefully we'll take a look soon. |
As per your original sample you're using |
I think this is an expected behavior - you're launching a window on a background thread. Doing otherwise would result in a jarring user experience. |
@fvanheeswijk Please give the above-mentioned fixes a try. I'm closing this issue for now as it sounds like it's By Design. Thanks! |
@RussKie This behavior works normally, it is only when the WebView2 control is involved that it does not work. @maurawinstanley This does seem to have some effect but not a consistent one. The first time you press the button to open a new form it does seem to work, but when you press it again it opens the forms behind the current window again. And even more peculiarly sometimes it does manage to open it in front again, so this does not seem a reliable workaround. @champnic I'm still convinced the root of the issue can be resolved by calling AllowSetForegroundWindow from the browser process. I see no reason why you would not call it because the browser process is expected to be one with the application process, they run in the same window (visually) after all. |
@fvanheeswijk Using the provided workaround triggered the new form to be created in the foreground for me every time (multiple times, I tried up to 20). Do you mind sharing how you are initializing the WebView? |
This is the code (below) I am using @maurawinstanley, I had to add the So I wait for the main form to open, press F8, then press on the 'Open new form' button then the new form always gets opened on top. After that I focus the original form again and repeat the same and then it opens under (most of the time).
I'm using the (newest) 1.0.865-prerelease version. |
@fvanheeswijk Can you try changing the newForm.Shown line to this: How are you setting up WebView2, do you call EnsureCoreWebView2Async? |
Hi @fvanheeswijk just following up one more time about this, if not, we will close out the issue! |
@maurawinstanley We will try this workaround at a later point in time, however we still believe that calling AllowSetForegroundWindow is the correct course of action. So according to us this issue is not fixed, it should just work out of the box. Currently we are running a different workaround that seemed to work but it fails if the newly opened window is maximized, hence why we do not want to rely on workarounds in a production application, we need a proper fix. |
We have tried the suggested workaround in our actual application but cannot get it to work. We tried many things but none are successful. We still kindly request Microsoft to ensure that the browser allows other windows to be stacked on top of it modelessly, because it visually is part of the process/application that hosts it. |
@fvanheeswijk We are looking into this, thanks for your patience! |
@fvanheeswijk Thanks for your patience, the fix should be in Canary later this week, closing this issue, feel free to re-open it if you find that the issue is not resolved. |
@maurawinstanley Thank you! We can confirm that it works 😃 |
We are seeing the following issue in our application: When we click on links to open objects within our application they are displayed underneath the current form (main application window). Strangely enough it does behave correctly if we select the link via tab and then enter it to open the link.
A reproducible example is available below:
In here it basically reproduces in the same way:
We expect the form to be opened on top of the current form in all cases. Also please be advised that the form is not supposed to be modal.
AB#27643346
The text was updated successfully, but these errors were encountered: