MicrosoftEdge / MicrosoftEdge/WebView2Feedback
Validated event not fired properly
@bradp0721 is already working on this.
Since Nov 28, 2022.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
If the WebView2 control loses focus it should raise the "Validated" event. However, this will only happen if WebView2 has gained focus by pressing the TAB key. If it gains focus by clicking the mouse, the "Validated" event will not be fired on subsequent loss of focus.
Microsoft.Web.WebView2 version 1.0.1418.22
Below is the source code to reproduce the problem.
How to reproduce the problem:
- Click on textbox1
- Click on textbox2 (textbox2 gets focus)
- Click on webview2 (webview2 gets focus)
- Click on textbox1 (textbox1 gets focus)
- Click on textbox2 (textbox2 gets focus)
In the console output you will see:
textbox1 validated
textbox2 validated
textbox1 validated
However, the expected result should be:
textbox1 validated
textbox2 validated
webView2 validated
textbox1 validated
However, if you use the TAB key, everything works as expected:
- Click on textbox1
- Press the TAB key (textbox2 gets focus)
- Press the TAB key (webview2 gets focus)
- Click on textbox1 (textbox1 gets focus)
- Press the TAB key (textbox2 gets focus)
In the console output you will see:
textbox1 validated
textbox2 validated
webView2 validated
textbox1 validated
Source code to reproduce the problem. Create new WinForms project, edit form1.cs.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var textbox1 = new TextBox();
textbox1.TabIndex = 0;
textbox1.Parent = this;
textbox1.Validated += (_, _) => Console.WriteLine("textbox1 validated");
var textbox2 = new TextBox();
textbox1.TabIndex = 1;
textbox2.Parent = this;
textbox2.Left = 200;
textbox2.Validated += (_, _) => Console.WriteLine("textbox2 validated");
var webView2 = new WebView2();
textbox1.TabIndex = 2;
webView2.Top = 30;
webView2.Width = Width;
webView2.Height = Height-30;
webView2.Parent = this;
webView2.Source = new Uri("https://www.google.com");
webView2.Validated += (_, _) => Console.WriteLine("webView2 validated");
}
}
To see the console, change OutputType from "WinExe" to "Exe"
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1418.22" />
</ItemGroup>
</Project>
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.