Active window is not correct sometimes when DockingWindow include WebView2

Docking/MDI for WPF Forum

The latest build of this product (v22.1.4) was released 2 months ago, which was before this thread was created.
Posted 6 days 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 (2)

Posted 5 days 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 5 days ago by Yuki
Avatar

Hello,

Thank you for analyzing it.

I will report this to WebView2 team.

Add Comment

Please log in to a validated account to post comments.