Skip to content

Multiple WebView2 control have focus sometimes. #3161

Open
@YuuukiA

Description

@YuuukiA

Description

I'm using multiple WebView2 control in WPF application.
It seems that multiple WebView2 control have focus sometimes.
Would you please check it?

Version
SDK: WebView2 1.0.1518.46
Runtime: Microsoft.Web.WebView2 1.0.1518.46
Framework: WPF, .Net6
OS: Win10

Repro Steps

I made a simple app as the following.

  1. Launch app.
  2. Press "F2" key.
    --> Sub window is shown.
  3. Set cursor to "Search" Textbox in the following order.
    View1 -> View2 -> Sub window -> View2
    --> Cursor is blinking in both View1 and View2.
<Window
    x:Class="WpfApp17.MainWindow"
    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"
    Title="Test"
    MinWidth="250"
    WindowStartupLocation="CenterScreen">

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

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

Code behind

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

namespace WpfApp17
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            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() { Title = "Sub window" };
                webView.Source = new Uri("https://docs.microsoft.com/en-us/");
                w.Content = webView;

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

Screenshots
image

Additional context

AB#43457303

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingtrackedWe are tracking this work internally.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions