我试图在 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”。
你知道如何解决这个问题吗?
最佳答案
我认为路径不正确。
你的项目中有/Html/par
目录吗?其次,index.html 是否设置为内容?
尝试
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
关于javascript - 在 WebBrowser 控件中加载本地文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11342153/