Chapter 13. Using Screen Rotation and Auto Sizing

With Windows Phone 7 you can build your application to run in portrait or landscape orientation, or you can allow your application to work in either orientation based on how the user is holding the phone. In this lesson you will learn how to enable support for all three of these page orientations.

SETTING SCREEN ORIENTATION

When you create a new Windows Phone 7 project, by default Visual Studio includes a MainPage.xaml page, which is your application's start page. It has its Orientation and SupportedOrientations set to Portrait in the opening PhoneApplicationPage tag. If you were to add a new Windows Phone Landscape Page to the project, it would have its Orientation and SupportedOrientations set to Landscape. What if you want the contents of either page to rotate based on how the user is holding the phone?

To allow your application to rotate between portrait and landscape orientations automatically as the position of the phone changes, you set the page's SupportedOrientations property to PortraitOrLandscape. While this enables the page to be viewed in either orientation, the page might not behave as you intend it to when its orientation is changed. If you construct the page layout based on landscape orientation as shown in Figure 13-1, and the page is viewed in portrait orientation as shown in Figure 13-2, some of the controls on the page may end up not being displayed on the screen.

This can happen if the Margin property of the control ...

Get Windows® Phone 7 Application Development 24-Hour Trainer 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.