Loading a Local HTML File in the WebBrowser Control

There was an interesting post over on the official WP7 Development forums. The nature of it wasn’t necessarily interesting, but it was something that seems quite straightforward on the surface but required a bit more thinking that I had initially thought. You can see the question here, but it was essentially “How do you display a local HTML file in a WebBrowser control“. I’ve never used Silverlight before Windows Phone 7, so the answer may be obvious to some, but I figured I’d write a quick blog post about it anyway for those who don’t know. The easy way to do this is to simply have your entire HTML stored in a string variable and call the WebBrower.NavigateToString() method. This works, but can be quite tedious. Firstly, if your HTML is long, it could quickly become tedious copy and pasting into the VS IDE and making sure that all necessary characters are escaped so that the entire HTML content is one string. Secondly, if you have multiple HTML files, then you’d have to do that for each HTML file.I figured there must be another, probably better, way of doing it.

Read more of this post

Advertisements