-
Notifications
You must be signed in to change notification settings - Fork 504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CoreWebView2 is null when accessing it from another XAML Window in the same project #822
Comments
I've tested the following code, which seems to work. Create a new project named: WebView2WpfTest VS 2017:
VS 2019:
Open Solution Explorer
Add WebView2 package
Modify MainWindow.xaml code
MainWindow.xaml
Modify MainWindow.xaml.cs code
MainWindow.xaml.cs
Add AnotherWindow window
Modify AnotherWindow.xaml code
AnotherWindow.xaml
Modify AnotherWindow.xaml.cs code
AnotherWindow.xaml.cs
Modify App.xaml (change StartupUri from MainWindow.xaml to AnotherWindow.xaml)
App.xaml
|
@saf-itpro the engineering team responded on the linked issue. Please review. Thanks. |
I'll go ahead and close this issue now. Thanks. |
WPF WebView2 Control is inside the
MainWindow.xaml
(shown below). When calling ExecuteScriptAsync(...) from a Button click event insideMainWindow.xaml.cs
(code shown below), it works fine. But when accessingWebView2
control from another classAnotherWindow.xaml.cs
(in the same project) and call the sameExecuteScriptAsync(...)
method it complains aboutCoreWebView2
being nullQuestion: What I may be missing, and how can it be resolved?
MainWindow.xaml:
Remark 1: Following works fine when button and its click event is inside
MainWindow.xaml.cs
The debug mode shows below that
CoreWebView2
is not null (and hence the code works):Remark 2: Following does NOT work when button and its click event is inside another window
AnotherWindow.xaml.cs
in the same project but accessing theWebView2
control of theMainWindow.xaml
The debug mode inside the
AnotherWindow.xaml.cs
shows below thatCoreWebView2
is not null (and hence throws the error: Object reference not set):The text was updated successfully, but these errors were encountered: