-1

I am having trouble displaying html onto a web browser. I am using the method "Deployment.Current.Dispatcher.BeginInvoke" but it wont displaying anything. What I am trying to do is getting html from a server as a string and displaying in my web browser. I can display messagebox but i cant send the string that contains html onto my web browser. Here is the snippet of code that is giving me trouble:
Deployment.Current.Dispatcher.BeginInvoke( () => { WebBrowser webBrowser1 = new WebBrowser(); //MessageBox.Show(responseString); webBrowser1.NavigateToString(responseString); });

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Have you tried to navigate to a string you've written yourself? Like var responseStringMock = "

    Hello world

    "; ?
    – Kris Selbekk Aug 07 '12 at 22:43
  • I have on a separate project and it works fine. But if i try to do it in the current project that I am having trouble with, it tells me that there is a invalid cross thread. – Daniel Gopar Aug 07 '12 at 22:48

1 Answers1

1

I think the reason for this error is because you're creating the WebBrowser-instance inside your callback code - which you shouldn't do anyways (because how are you going to display it on the screen? If you are trying to go from your application into the main WebBrowser-app (IE), you should use WebBrowserTask instead.

So either:

  1. you are trying to show a WebBrowser inside your application view (hybrid style). If so, you should call .NavigateToString(string html) on the WebBrowser you're displaying instead of creating another instance.
  2. you are trying to show downloaded HTML in the main browser app on your phone (Internet Explorer). This can't be done by handing over the HTML directly, you would have to send it the URI-object where the browser can find it itself.

Or of course, the problem is somewhere else in your code. This is the best I could answer with the information and code you have provided.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Kris Selbekk
  • 7,438
  • 7
  • 46
  • 73