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.