2011-11-08 79 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)); –

相關問題