How to Handle Orientation Changes in Your WP7 Application


Mobile devices have a big constraint compared to desktops – their screen
size. Also, they can be handled in a variety of orientations. On the other
hand, they are always available, in your pocket or purse, at any time you want
to use them.

The mobility of the Windows Phone
7 device ensures that they can be used anywhere. This also brings the
possibility that the orientation in which they are used is not a pre-defined.
The devices can be held in any orientation and when the orientation changes
from portrait to landscape, a smartphone application should change how they
operate to maximize the value proposition of the new orientation.

In this article, we will explore how to handle orientation changes in your

To configure your Windows Phone application for orientation support, you
need to set the SupportedOrientations property. The possible values for this
property are Portrait, Landscape and PortraitOrLandscape.

To enable orientation support, we need to set this property to

Let us explore this hands-on by switching the scrolling orientation in a
demo Windows Phone 7 application.


Create a new Silverlight for Windows Phone project in Visual Studio called

In the XAML for the main page, change the SupportedOrientations property to

mc_Ignorable="d" d_DesignWidth="480" d_DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"

Now, go ahead and add an instance of the ScrollViewer control. We need this
control because it has a unique property; it allows you to scroll through its

Inside the ScrollViewer instance, add a StackPanel control, which will host
our contents.

Inside the StackPanel control, drag and drop a few controls like Button,
RadioButton, TextBlock and TextBox. For controls that have a width property,
make sure you set the width to the maximum possible that can fit.

To ensure that you have the right width, copy paste the following code,
which will add the ScrollViewer, StackPanel and a few dummy controls.

//MainPage.xaml snippet

More by Author

Must Read