WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

"CoreWebView2InitializationCompleted" not called on ViewModel when runtime is not installed

Open gustavocalheiros opened this issue 4 years ago • 1 comments

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);
}

} `

AB#33157035

gustavocalheiros avatar May 06 '21 09:05 gustavocalheiros

Thanks for the bug report @gustavocalheiros - I've added it to our backlog.

champnic avatar May 08 '21 03:05 champnic