Silverlight for Windows Phone supports portrait and landscape screen orientations. This QuickStart describes how to work with orientation changes in Windows Phone.
This QuickStart contains the following sections:
Windows Phone supports the following screen orientations:
Users can simply rotate the device to initiate a change from one orientation to another. When you're testing your application in the emulator, you can switch the screen orientation by clicking the buttons in the emulator toolbar. The orientation buttons have rectangles with arrows that indicate the orientation change.
In portrait orientation, the page is oriented vertically so that the height of the page is greater than its width.
In either of the two landscape orientations, the Status Bar and the Application Bar remain on the side of the screen that has the Power and the Start button, respectively. Landscape left has the Status Bar on the left and landscape right has the Status Bar on the right.
Portrait is the default orientation for applications and you must add additional code to support landscape. You can't specify only left or only right landscape orientation. If you support landscape orientation, you must support both left and right. To specify that your application supports portrait and landscape, you must set the SupportedOrientations property to PortraitOrLandscape either in the XAML or in the code.
There are different ways to display content in either portrait or landscape orientation. Two techniques are scrolling and grid layout.
The scrolling technique uses a StackPanel control that is placed within a ScrollViewer control. Use this technique if you're displaying content in a list or if you have different controls appearing one after another on the page. The StackPanel enables you to order the child elements one after another in your application and the ScrollViewer control enables you to scroll through the StackPanel if the UI elements don't fit on the screen when you switch from portrait to landscape.
To use the scrolling technique, you typically perform the following steps.
The following example shows a StackPanel and several controls within a ScrollViewer.
The following illustrations show the scrolling behavior for portrait and landscape orientations. The portrait orientation doesn't require scrolling, but the landscape orientation does require scrolling.
The grid layout technique positions UI elements in a Grid. When an orientation change occurs, you programmatically reposition elements into different cells of the Grid.
To use the grid layout technique, you typically perform the following steps.
The following example creates a 2 x 2 Grid to position an image and a collection of buttons. The OrientationChanged event handler repositions the elements within the Grid when the orientation is changed.
The following illustrations show the grid layout behavior for portrait and landscape orientations. In the portrait orientation, the buttons are positioned on the bottom. In the landscape orientation, the buttons are positioned on the right.
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/