Categories: Blog

Silverlight for Windows Phone Programming Tip #8

One of the remarkable aspects of Windows Phone 7’s WebBrowser control is that you can build an entire Web site in isolated storage, point the WebBrowser control to it, and view the Web site on your phone. Once IE for Windows phones comes to support HTML5 (and that day can’t come soon enough, IMHO), this, I believe, will be a useful mechanism for packaging HTML5 apps so that they look and feel like native phone apps. Even now, using a WebBrowser control as a window into local HTML content provides a way to deploy HTML-based help systems to the phone. And I’m sure there are other uses for it that I haven’t thought of.

To demonstrate how to use WebBrowser to view locally stored content, I built a sample site in HTML and wrote the pages, images, and style sheets into isolated storage. Relative links allow the user to navigate among the pages. The home page looks like this:

Here’s the HTML source for the page:

 

<html>

<head>

<meta name="viewport" content="width=480, user-scalable=yes" />

<link href="styles.css" rel="stylesheet" type="text/css" />

</head>

<body>

<img src="Images/BobCat.jpg" />

<h1>BVM BobCat</h1>

<p>Nullam fermentum tincidunt neque in fringilla...</p>

<a href="Page2.html">Next</a>

</body>

</html>

 

Notice the META element. It’s something you’ll almost invariably need if you build HTML content for Windows phones. If you remove the element, the page renders this way on the phone:

The META element provides a hint of sorts informing the WebBrowser control what the “native” width of the page is. I set it to 480, which is the width of the screen and the width of the image at the top of the page. With this element in place, the WebBrowser control happily sets the initial zoom level so that the page fills the width of the screen. Furthermore, the user-scalable=yes attribute indicates that the user should be able to zoom in and out using pinch gestures. To prevent users from zooming in and out, you can set this attribute to no.

There’s nothing complicated about <meta name=”viewport” content=”…” />, but if you don’t know that it exists, life with HTML on a Windows phone is measurably less pleasant.

Jeff Prosise

Recent Posts

8-Step AWS to Microsoft Azure Migration Strategy

Microsoft Azure and Amazon Web Services (AWS) are two of the most popular cloud platforms.…

2 weeks ago

How to Navigate Azure Governance

 Cloud management is difficult to do manually, especially if you work with multiple cloud…

3 weeks ago

Why Azure’s Scalability is Your Key to Business Growth & Efficiency

Azure’s scalable infrastructure is often cited as one of the primary reasons why it's the…

1 month ago

Unlocking the Power of AI in your Software Development Life Cycle (SDLC)

https://www.youtube.com/watch?v=wDzCN0d8SeA Watch our "Unlocking the Power of AI in your Software Development Life Cycle (SDLC)"…

2 months ago

The Role of FinOps in Accelerating Business Innovation

FinOps is a strategic approach to managing cloud costs. It combines financial management best practices…

2 months ago

Azure Kubernetes Security Best Practices

Using Kubernetes with Azure combines the power of Kubernetes container orchestration and the cloud capabilities…

2 months ago