>我正在使用以下链接中的代码:在 WPF Web 浏览器控件中显示字符串中的 html
它运行良好,除非我删除包含 html 的项目,e.NewValue
变得null
并且我得到一个例外。有没有办法将 Web 浏览器控件返回到空白屏幕?
我找到了这个。有人有更好的吗?
if (wb != null)
{
if (e.NewValue != null)
wb.NavigateToString(e.NewValue as string);
else
wb.Navigate("about:blank");
}
编辑:
正如 poby 在注释中提到的,对于 .NET 4+,请使用:
if (wb != null)
{
if (e.NewValue != null)
wb.NavigateToString(e.NewValue as string);
else
wb.Navigate((Uri)null);
}
我只是将WebBrowserLabel的DocumentText设置为字符串。空。