WebBrowser control wont display content from a object source
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();
}
- Your HTML looks malformed.
<body>
tags aren't optional - A WebBrowser is a control that needs to be added to a form -- it is not itself a form.
Try to do document writing in Navigated event
Hope this helps
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)
精彩评论