【发布时间】:2021-10-15 23:29:57
【问题描述】:
我正在尝试创建一个添加了 html 文件的示例桌面 wpf 应用程序。我正在使用 webview2。
这是我的标记:
<Wpf:WebView2 HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="webContainer" />
和我的代码:
public MainWindow()
{
InitializeComponent();
string url1 = Directory.GetCurrentDirectory() + "\\site\\index1.html";
webContainer.CoreWebView2.Navigate(url1);
}
我在Navigate() 行收到以下错误
用户未处理的异常
System.NullReferenceException :对象引用未设置为对象的实例。
`Wpf.Webview2.CoreWebview2.get` returned null.
谁能帮我找出错误?
【问题讨论】:
-
Navigate() 不断发送空异常,但使用 Source() 解决了异常。 webContainer.Source=(uri1);解决了。还将 XAML 中的名称更改为 x:Name
标签: c# .net wpf visual-studio webview