WebBrowser 控件不会显示来自对象源的内容
我得到一些从外部源返回的 HTML 并设置为一个简单的字符串。但是,当我设置控件的 DocumentText 参数时,没有任何变化。这似乎是一个常见问题,我尝试了以前帖子的结果但无济于事。
另外 .show() 方法似乎没有弹出窗口?在下面的代码中,它创建一个新窗口,设置一些参数并尝试打开浏览器。
private void createWindow(String text)
{
if (text == null) throw new ArgumentNullException("Nothing has been returned, possible MBean Failure");
Window a = new Window();
a.Title = "Output";
RichTextBox rtb = new RichTextBox();
rtb.FontSize = 12;
rtb.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#639FBE"));
rtb.IsReadOnly = true;
rtb.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
rtb.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
rtb.Margin = new Thickness(15);
Grid myGrid = new Grid();
a.Content = myGrid;
myGrid.Children.Add(rtb);
rtb.AppendText(text);
a.Height = myGrid.Height;
a.Width = myGrid.Width;
if (text == null) throw new ArgumentNullException("Nothing has been returned, possible Failure");
browser.Navigate("abount:blank");
HtmlDocument doc = browser.Document;
browser.Document.OpenNew(true);
doc.Write("<HTML>" + text + "</HTML>");
browser.DocumentText = doc.ToString();
browser.Show();
// a.ShowDialog();
}
i get some HTML returned from an external source and set to a simple string. However when i set the DocumentText param of the control nothing gets changed. This seems to be a common issue, and ive tried the results from previous posts to no avail.
Also the .show() method doesnt seem to pop the window up? In the code below it creates a new window, sets some params and tried to open the browser.
private void createWindow(String text)
{
if (text == null) throw new ArgumentNullException("Nothing has been returned, possible MBean Failure");
Window a = new Window();
a.Title = "Output";
RichTextBox rtb = new RichTextBox();
rtb.FontSize = 12;
rtb.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#639FBE"));
rtb.IsReadOnly = true;
rtb.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
rtb.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
rtb.Margin = new Thickness(15);
Grid myGrid = new Grid();
a.Content = myGrid;
myGrid.Children.Add(rtb);
rtb.AppendText(text);
a.Height = myGrid.Height;
a.Width = myGrid.Width;
if (text == null) throw new ArgumentNullException("Nothing has been returned, possible Failure");
browser.Navigate("abount:blank");
HtmlDocument doc = browser.Document;
browser.Document.OpenNew(true);
doc.Write("<HTML>" + text + "</HTML>");
browser.DocumentText = doc.ToString();
browser.Show();
// a.ShowDialog();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
标记不是可选的
<body>
tags aren't optional尝试在导航事件
希望这会有所帮助
Try to do document writing in Navigated event
Hope this helps
您是否尝试过
NavigateToString
?这似乎比对文档进行任何操作要容易得多。(如果您尝试过失败的事情,您应该顺便提及它们是什么以及为什么它们不起作用)
Have you tried
NavigateToString
? That seems to be far easier than doing anything with the document.(If you have tried things that failed you should mention what they were and why they did not work by the way)