1

我试图在 Windows Phone 7.1 上的 WebBrowser 中加载本地文件,但我总是遇到异常或空白页。

我试过了

Stream stream = Application.GetResourceStream(
                   new Uri("./Html/par/index.html", 
                   UriKind.Relative)).Stream;
using (StreamReader reader = new StreamReader(stream))
{
    // Navigate to HTML document string
    this.webBrowser.NavigateToString(reader.ReadToEnd());
}

这是触发空白页。

我将 index.html 和所需的所有文件(css/js)设置为 Content 并将 IsScriptEnable 设置为“true”。

你知道如何解决这个问题吗?

4

1 回答 1

2

我认为路径不正确。

你的项目中有/Html/par目录吗?其次是 index.html 设置为 content 吗?

尝试

var rs = Application.GetResourceStream(new Uri("myFile.html", UriKind.Relative));
using(StreamReader sr = new StreamReader(rs.Stream))
{
    this.webBrowser.NavigateToString(sr.ReadToEnd()); 
}

这可能会有所帮助 http://phone7.wordpress.com/2010/08/08/loading-a-local-html-file-in-the-webbrowser-control/

这可能有助于理解资源和内容之间的差异 http://invokeit.wordpress.com/2011/09/30/images-and-build-actio-settings-in-wp7/

此链接详细说明如何加载文件和其他链接文件 http://transoceanic.blogspot.co.uk/2011/07/wp7-load-local-html-files-and-all.html

于 2012-07-05T10:33:39.287 回答