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)
Avatar

Hello,

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.
    <sampleBrowser:ProductItemControl
        x:Class="ActiproSoftware.ProductSamples.DockingSamples.QuickStart.PrimaryDocumentTracking.MainControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"
        xmlns:sampleBrowser="clr-namespace:ActiproSoftware.SampleBrowser"
        xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
        xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf">
    
    ...
                                <docking:DocumentWindow
                                    Title="Document3.txt"
                                    Description="Text document"
                                    FileName="Document3.txt"
                                    ImageSource="/Images/Icons/TextDocument16.png">
                                    <wv2:WebView2 docking:InteropFocusTracking.IsEnabled="True" Source="https://docs.microsoft.com/en-us/" />
                                    <!--<TextBox BorderThickness="0" Text="The third document." TextWrapping="Wrap" />-->
                                </docking:DocumentWindow>
    

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
Avatar

Hello,

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 3 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.