开发者

How do I let a user browse HTML/WebSite content without launching the browser (need an inline browser)?

I'm creating an app on Windows 开发者_运维技巧Phone 7 that lets folks read offline HTML content. Is there a way to show an inline browser or HTML viewing control?


The WebBrowser control allows you to display arbitrary HTML.

There are two methods on the WebBrowser control you can use to display HTML:

  1. Navigate() will display the contents of a file located at the supplied URL. This file can be in IsolatedStorage or on a server.
  2. NavigateToString() will display the html string you give it.

In your case I'm guessing you'd use a WebClient object to download the webpage to offline storage, then the Navigate method to display it.

However, the benefit of NavigateToString is that you can munge the string on the way in to do some cool (or essential) stuff like style the page so it matches perfectly with the current phone theme, or catch all link clicks and make them pop in the external browser (otherwise they load in the very same WebBrowser control).

I've documented the details of styling and link clickery here.


Yes, there's a WebBrowser control in Microsoft.Phone.Controls

If you then save your (offline) files to IsolatedStorage you can then view the file via a call like this from code:

webBrowser1.Navigate(new Uri("offline-file-name.html", UriKind.Relative));

Things to note:

  • You can use directories within isolated storage. Just specify the whole path in the Uri.

  • If navigating between offline pages, all paths must be relative.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜