Active window is not correct sometimes when DockingWindow include WebView2

Docking/MDI for WPF Forum

Posted 1 year ago by Yuki
Version: 22.1.4
Platform: .NET 6.0
Environment: Windows 10 (64-bit)
Avatar

Hello,

I'm using WebView2 in DockingWindow.

Sometimes active window is not correct.

Would you please check it?

I will send source code.

<Source code>

I modified "ActiproSoftware.ProductSamples.DockingSamples.Demo.SimpleIde" of sample project.

  • MainControl.xaml
    • Add property of "dockSite"
      • FloatingWindowShowInTaskBarMode="Never" 
    • Put WebView2 control in "outputToolWindow".
  • EditorDocumentWindow.xaml
    • Put WebView2 control in Grid control.

<Procedure>

  1. Show new text file. ([File] menu - [New] - [Text File])
    ⇒"Document1.txt"
  2. Float document window of "Document1.txt".
  3. Select window as the following
    - "Document1.txt" -> "About.txt" -> "Output"
    - "Document1.txt" -> "Output" -> "About.txt"

Comments (5)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Thank you for the sample, but I think this is a bug in WebView2.  You'll notice in your video that when the problem occurs, both WebView2 instances in the main Window have the cursor blinking.  WebView2 has always had issues with proper focus tracking in WPF applications, and providing focus events, moreso than with other interop controls.

As a test to verify this, I made a simple app that doesn't use our controls at all:

<Window x:Class="WpfApplication1.Window9"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wv2="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
        WindowStartupLocation="CenterScreen"
        Width="1200"
        Height="900"
        MinWidth="250"
        Title="Test">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <wv2:WebView2 Source="https://docs.microsoft.com/en-us/" />
        <wv2:WebView2 Grid.Row="1" Source="https://docs.microsoft.com/en-us/" />
    </Grid>
</Window>

And code behind:

using Microsoft.Web.WebView2.Wpf;
using System;
using System.Windows;
using System.Windows.Input;

namespace WpfApplication1 {

    /// <summary>
    /// Interaction logic for Window9.xaml
    /// </summary>
    public partial class Window9 : Window {
        public Window9() {
            InitializeComponent();
        }

        protected override void OnKeyDown(KeyEventArgs e) {
            base.OnKeyDown(e);

            if (e.Key == Key.F2) {
                var w = new Window();
                w.Width = 500;
                w.Height = 400;

                var webView = new WebView2();
                webView.Source = new Uri("https://docs.microsoft.com/en-us/");
                w.Content = webView;

                w.Owner = this;
                w.Show();
            }
        }

    }
}

To reproduce...

1) Run the app.

2) Press F2 to open the second Window.  

3) Click in the textbox in the upper webview of the main Window.

4) Click in the textbox in the webview of the second Window.

5) Click in the textbox in the lower webview of the main Window.

You now see both webviews in the main Window have blinking carets.  This is only with pure WPF controls and highlights the issue.

You may wish to report this to the WebView2 team so they can solve the focus issues they have.


Actipro Software Support

Posted 1 year ago by Yuki
Avatar

Hello,

Thank you for analyzing it.

I will report this to WebView2 team.

Posted 1 year ago by Yuki
Avatar

Hello,

I had reported this issue to WebView2 team and have recieved reply today.

Would it be possible to add below workaround to your software?

Multiple WebView2 control have focus sometimes. · Issue #3161 · MicrosoftEdge/WebView2Feedback (github.com)

Posted 1 year ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Unfortunately I don't believe implementing their workaround will be possible in our code.  Our docking windows can host any control, not just WebView2 and we have to focus whichever child control is in them.  We can't focus a hosting WPF Window ourselves or our focus logic will not be accurate for everyone else. 

Since all of this is a confirmed Microsoft bug, I would strongly urge you to push them to fix the focus issue on their end, which would negate the need for any workaround anyhow. 

You can try implementing their workaround in your code, since it seems to be for the main WPF Window anyhow.  Or you could look at alternate browser options, such as Cecil.


Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was before the next post in this thread.
Posted 20 days ago by Yuki
Avatar

Hello,

Regarding to WebView issue which I had reported previously, it seems to be fixed in latest WebView2 component.

However, we have encountered other issue of active window.

Would you please check it?

  

I will send sample project and video by email.

[Modified 20 days ago]

Add Comment

Please log in to a validated account to post comments.