Primary document/Active window is not switched when use WebView2

Docking/MDI for WPF Forum

Posted 2 years ago by Yuki
Version: 22.1.1
Platform: .NET 5.0
Environment: Windows 10 (64-bit)


I'm using WebView2 in document window.

Primary document/Active window is not switched properly if I set 'docking:InteropFocusTracking.IsEnabled="True"' to WebView2.

If I don't set 'docking:InteropFocusTracking.IsEnabled="True"', it is switched properly. (But other focus problem occur...)

Would you please check it?

If my code is not properly, could you please give me some advice?

You can see the problem in "Primary Document Tracking" sample with adding the following code.

  • Change "Document3.txt" content to WebView2 and set "docking:InteropFocusTracking.IsEnabled" to true.
                                    Description="Text document"
                                    <wv2:WebView2 docking:InteropFocusTracking.IsEnabled="True" Source="" />
                                    <!--<TextBox BorderThickness="0" Text="The third document." TextWrapping="Wrap" />-->

When switch tab from "Document1.txt" to "Document2.txt", primary document/active window is changed to "Document2.txt".

When switch tab from "Document3.txt" to "Document1.txt", primary document/active window is still "Document3.txt".

Comments (1)

Answer - Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA


It appears that for some reason, WebView2 sometimes sends itself a WM_SETFOCUS message when it is hidden in WPF.  What ends up happening is that clicking Document1's tab sets DockSite.ActiveWindow to Document1, but then this WM_SETFOCUS message occurs in WebView2 after, triggering InteropFocusTracking to think the WebView2 now has focus, so ActiveWindow then gets set to its tab right away.

It seems like a bug in WebView2 since no other interop controls we've seen do this.  That being said, we were able to add some code to detect this scenario and have resolved it for the next maintenance release.

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.