2011-11-08 78 views
3

我需要帮助在Windows Phone 7应用程序中显示webbrowser中的HTML文件。本地HTML文件 - WebBrowser - Windows phone 7

我在我的wpf-silverlight项目中有一个html文件作为资源。现在,当用户点击我的应用程序中的帮助按钮时,我需要在web浏览器中显示此HTML。

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)) 

请帮帮忙!

我已经改变了这样的代码,但现在我得到这个错误:无效的URI:一个端口用':'表示,但不能被解析。

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

您可以通过获取HTML文件的内容使用方法NavigatedToString WebBrowse对象,并把它作为该方法的参数。

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

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

+0

这里是我的代码和我得到这个eror(无效的URI:端口发出信号以“:”但无法解析)开放的URI =新的URI(@“包:/ /application:AppHelp.html“,UriKind.Absolute); Stream stream = Application.GetResourceStream(uri).Stream; using(StreamReader reader = new StreamReader(stream)) { //导航到HTML文档字符串 this.webBrowser1.NavigateToString(reader.ReadToEnd()); } – Pavan

+0

谢谢,达米安.......真棒 – Pavan

+0

设置您的HTML文件的构建选项为“content”并获取流:Application.GetResourceStream(new Uri(“yourfilename.html”,UriKind.Relative)); –

相关问题