Local HTML File - WebBrowser - Windows phone 7

2019-02-19 02:08发布

问题:

I need help in displaying HTML File in webbrowser in Windows phone 7 app.

I've an html file in my wpf-silverlight project as resource. Now When the user click on Help button in my App, i need to display this HTML in webbrowser.

Here is the code, which is giving me an error -

webBrowser1.Navigate(new Uri("AppHelp.html",UriKind.Relative))

But, if i use this code, It's loading fine

webBrowser1.Navigate(new Uri("http://mywebsite.com/AppHelp.html",UriKind.Relative))

Please help!

I've change code like this now, but now i'm getting this error:Invalid URI: A Port is signaled with ':' but could not be parsed.

   Uri uri = new Uri(@"pack://application:AppHelp.html", UriKind.Absolute);
    Stream stream = Application.GetResourceStream(uri).Stream;
    using (StreamReader reader = new StreamReader(stream))
    {
        // Navigate to HTML document string
        this.webBrowser1.NavigateToString(reader.ReadToEnd());
    }

回答1:

You can use method NavigatedToString of WebBrowse object by getting content of html file and put it as parameter of this method.

http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.navigatetostring.aspx

samples at: http://blogs.msdn.com/b/mikeormond/archive/2010/12/16/displaying-html-content-in-windows-phone-7.aspx



回答2:

You can try this,

http://www.c-sharpcorner.com/uploadfile/raj1979/how-to-embed-html-file-in-windows-phone-7/

and for with image in html

you can this, Use local images in Webbrowser control

using IsolatedStorages