MicrosoftEdge / MicrosoftEdge/WebView2Feedback
"CoreWebView2InitializationCompleted" not called on ViewModel when runtime is not installed
Nobody has claimed this yet.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Description
I have a WPF application using WebView2 and Prism for MVVM.
I'm listening to the event "CoreWebView2InitializationCompleted" on both the code-behind, and on the ViewModel (via "prism:InvokeCommandAction"
In a normal situation, both methods are called (first the one on the code behind, and then the one on the ViewModel).
But when the Runtime is not installed, method on the code behind is called (correctly with WebView2RuntimeNotFoundException), but the one on the ViewModel is not. It happens only on this case, for any other exception both methods are called.
Version
SDK: 1.0.818.41
Runtime: 90.0.818.42
Framework: WPF, .NET 5.0, Prism (or MVVMLight).
OS: Win10 2004 build 19041.928
Repro Steps
1- Uninstall WebView2 runtime.
2- Compile and run the attached VS solution. testPrism.zip
OBS
Tested also with MvvmLight toolkit, same result.
=====
on MainWindow.xaml:
<wv2:WebView2 x:Name="WebView2"
Width="600"
Height="600"
CoreWebView2InitializationCompleted="WebView2_OnCoreWebView2InitializationCompleted"
>
<b:Interaction.Triggers>
<b:EventTrigger EventName="CoreWebView2InitializationCompleted">
<mvvm:InvokeCommandAction Command="{Binding MyCommand}" />
</b:EventTrigger>
</b:Interaction.Triggers>
</wv2:WebView2>
=====
On MainWindow.xaml.cs
`
public MainWindow()
{
InitializeComponent()
this.Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.WebView2.CreationProperties = new CoreWebView2CreationProperties() { UserDataFolder = Path.GetTempPath() };
// Uncomment to simulate COMException.
//this.WebView2.CreationProperties = new CoreWebView2CreationProperties() { UserDataFolder = "C:\\Windows" };
this.WebView2.Source = new Uri(((MainWindowViewModel)this.DataContext).Url);
}
private void WebView2_OnCoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
Trace.WriteLine("Code Behind \n Exception = " + e.InitializationException);
}`
====
On ViewModel:
`
class MainWindowViewModel : BindableBase
{
public MainWindowViewModel()
{
Url = https://google.com/
MyCommand = new DelegateCommand<CoreWebView2InitializationCompletedEventArgs>(Submit);
}
public DelegateCommand<CoreWebView2InitializationCompletedEventArgs> MyCommand { get; set; }
public string Url { get; set; }
void Submit(CoreWebView2InitializationCompletedEventArgs e)
{
Trace.WriteLine("ViewModel: \n Exception = " + e.InitializationException);
}
}
`
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.
Research direction
Start with the attached test solution, MainWindow.xaml, and MainWindow.xaml.cs. Reproduce the behavior with the WebView2 runtime uninstalled, then compare the code-behind event handling with the Prism or MVVMLight command binding. Done means the ViewModel handler receives the initialization-completed event in the runtime-not-installed case as well.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100