Reputation: 2246
I am developing a browser app using Windows Phone 8 browser control.
The app download an external webpage using WebClient into a string in the background. Then the browser navigate to the content using
webBrowser.NavigateToString(str);
However, instead of rendering the page, the browser shows the HTML code. I thought since no changes were made to the string, NavigateToString
should handle it seamlessly. Or perhaps I am missing something.
So how do I display the HTML page instead of its code?
EDIT
Here's some of my code
webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(uri));
private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
PageString = e.Result;
}
...
webBrowser.NavigateToString(PageString);
Upvotes: 3
Views: 6873
Reputation: 13
Another Way:
wb.Navigate("");
do
{
Application.DoEvents();
} while ((wb.ReadyState != WebBrowserReadyState.Complete));
wb.Document.Body.InnerHtml = "Html";
Upvotes: 0
Reputation: 448
This is an issue with Windows Phone 8.
Here you have a workaround.
Upvotes: 5
Reputation: 69372
When you use DownloadStringAsync
, it also downloads the DOCTYPE
declaration. You can remove this and start your code with the <html>
block as NavigateToString
doesn't seem to like the <!DOCTYPE HTML>
declaration.
webClient = new WebClient();
webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
webClient.DownloadStringAsync(new Uri(uri));
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
//remove "<!DOCTYPE HTML>"
PageString = e.Result.Replace("<!DOCTYPE HTML>","").Trim();
}
webBrowser.NavigateToString(PageString);
Upvotes: 3
Reputation: 2085
Documentation for WebBrowser.NavigateToString says:
If the text parameter is not in valid HTML format, it will be displayed as plain text.
Can you check if str
is in valid HTML format?
private void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
PageString = e.Result;
webBrowser.NavigateToString(PageString);
}
Upvotes: 0