Click here to Skip to main content
Click here to Skip to main content

Support Multiple Orientations - Windows Phone 7

By , 12 Feb 2011
 

If you worked on Windows Mobile before, you probably remember all the work that had to be done to support different orientations on your Windows Mobile application. You had to create different layouts/resources and detect the orientation change to load the corresponding layout. In Windows Phone7, this is much easier to handle.

By default, Silverlight applications for Windows Phone 7 run in portrait mode. To support both portrait and landscape mode, we just need to add an attribute in the root of your main page XAML file.

SupportedOrientations="PortraitOrLandscape"

You can also restrict the orientation mode of your application by using the same attribute. For example, a game application (Silverlight) may be better viewed in landscape mode. In this case, the attribute would be set as follows:

SupportedOrientations="Landscape"

For applications that get text input, it may not be enough to just set the orientation property because the hardware keyboard will take some of the display area. For this case, you may need to manipulate the layout by trapping the OrientationChanged event in the code.

In the XAML, we will need to add the event attribute as:

OrientationChanged="PhoneApplicationPage_OrientationChanged"

In the code, we will write the handler as follows:

private void PhoneApplicationPage_OrientationChanged
	(object sender, OrientationChangedEventArgs e)
{
    string orientation = e.Orientation.ToString();
    
    //add logic to handle your layout
    base.OnOrientationChanged(e);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

ozkar garcia
Software Developer (Senior) OG-BITechnologies
United States United States
Member

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 2memberh3213 Feb '11 - 5:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 13 Feb 2011
Article Copyright 2011 by ozkar garcia
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid