Using the ViewBox Control

As an alternative to defining a viewport, you can use the ViewBox control. The ViewBox control enables you to resize content to fit available screen real estate while retaining the correct aspect ratio.

Imagine, for example, that you happen to have a picture of a Tesla and the picture measures 800px by 484px. You want the picture to fill the entire available space but not get distorted.

The page in Listing 11.5 demonstrates how you can wrap the picture in a ViewBox.

LISTING 11.5 Using the ViewBox Control (viewBox\viewBox.html)

<div data-win-control="WinJS.UI.ViewBox">    <img src="/images/tesla.jpg" /></div>

Figure 11.12 illustrates the appearance of the picture on a device with a resolution ...

Get Windows® 8.1 Apps with HTML5 and JavaScript Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.