問題タブ [webview2]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 同じプロジェクト内の別の XAML ウィンドウから CoreWebView2 にアクセスすると、CoreWebView2 が null になる
WPF WebView2コントロールはMainWindow.xaml(以下に示す) 内にあります。内部のボタン クリック イベントからExecuteScriptAsync(...)を呼び出すと(MainWindow.xaml.cs以下に示すコード)、正常に動作します。しかし、 (同じプロジェクト内の)WebView2別のクラスからコントロールにアクセスAnotherWindow.xaml.csし、同じメソッドを呼び出すと、nullExecuteScriptAsync(...)であると不平を言うCoreWebView2
質問: 不足している可能性があるものと、それを解決するにはどうすればよいですか?
MainWindow.xaml :
備考1:ボタンとそのクリックイベントが内部にある場合、以下は正常に機能しますMainWindow.xaml.cs
デバッグ モードはCoreWebView2、null ではないことを以下に示します (したがって、コードは機能します)。
備考 2AnotherWindow.xaml.cs : ボタンとそのクリック イベントが同じプロジェクト内の別のウィンドウ内にあるが、そのWebView2コントロールにアクセスしている場合、以下は機能しません。MainWindow.xaml
AnotherWindow.xaml.cs以下のショー内のデバッグモードCoreWebView2はnullではありません(したがって、エラーがスローされます:オブジェクト参照が設定されていません):


