我正在使用以下链接中的代码:在WPF WebBrowser控件中显示字符串中的html
它运作良好,除了当我删除包含HTML的项目,e.NewValue
成为null
和我得到一个异常。有没有办法将WebBrowser控件返回到空白屏幕?
我找到了这个。有人有更好的东西吗?
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);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句