如何在WPF中清除WebBrowser控件

时间:2022-08-25 00:05:35

I'm using the code from the following link: Displaying html from string in WPF WebBrowser control

我正在使用以下链接中的代码:在WPF WebBrowser控件中显示字符串中的html

It works well except when I delete the item containing the html, e.NewValue becomes null and I get an exception. Is there a way to return the WebBrowser control to a blank screen?

它很好用,除非我删除包含html的项目,e.NewValue变为null并且我得到一个例外。有没有办法将WebBrowser控件返回到空白屏幕?

2 个解决方案

#1


12  

I found this. Anyone have anything better?

我找到了这个。谁有更好的东西?

if (wb != null)
{
    if (e.NewValue != null)
        wb.NavigateToString(e.NewValue as string);
    else
        wb.Navigate("about:blank");
}

#2


0  

I just set the WebBrowserLabel's DocumentText to string.Empty.

我只是将WebBrowserLabel的DocumentText设置为string.Empty。

#1


12  

I found this. Anyone have anything better?

我找到了这个。谁有更好的东西?

if (wb != null)
{
    if (e.NewValue != null)
        wb.NavigateToString(e.NewValue as string);
    else
        wb.Navigate("about:blank");
}

#2


0  

I just set the WebBrowserLabel's DocumentText to string.Empty.

我只是将WebBrowserLabel的DocumentText设置为string.Empty。