Introduction:
In this article we are going to see about the Screen Orientations in Windows Phone 7 Development. As a Windows Phone 7 user we can see screen orientations are pretty simple just by titling the device and seeing the screen tilts as per the device, but as a developer when we see we have to handle much of the orientations programmatically as per the requirement. The in built sensors plays a major role when using the screen orientations in place for the developers to design the application looks easy for the end users to make use of the application effectively . [more]
In the Windows Phone 7 development by default the screens are in Portrait mode and we have 3 types of supported Screen Orientations as below
- Portrait
- Landscape(Left)
- Landscape(Right)
In order to use the orientation change with the Windows Phone development, in XAML page we need to make use of the SupportedPageOrientation properties. We can make use of these orientations in page level so that for each of the page we can specify a different orientation for better usability. The possible properties of the SupportedPageOrientation can be one of the below options
- Portrait
- Landscape
- PortraitOrLandscape
Let us jump start to see the step by step process on how to use the Windows Phone 7 Screen orientation effectively.
Steps:
Open Visual Studio 2010 and create a new Silverlight for Windows Phone 7 Application with a valid project name as shown in the screen below.
We can see a new Windows Phone 7 Application created with the designer windows and the XAML window. Now we can see the Orientations mentioned in the XAML code highlighted as shown in the screen below. By default we can see the Orientation is specified as Portrait as shown in the screen below.
XAML Code:
|
|
Now we will add some controls to have a good user look and feel as shown in the screen. Once we added the controls your complete XAML code will look like the below listing where we can see the SupportedOrientaion=”Portrait”. Now run the application by pressing F5 and we can see the application in Portrait orientation as shown in the screen below.
XAML Code:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Portrait Mode:
We can switch between the orientations right from the Emulator by clicking on the buttons as shown in the screen below.
Now let us change the Orientation in the XAML Code to Landscape as shown in the code below and run the application once again and see the application output as shown in the screen below.
XAML Code:
|
|
||
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Landscape:
Also we can control the orientation from the code behind programmatically by using one of the below code as per the requirement as shown in the screen below.
Code Behind:
|
|
|
|
|
|
|
|
|
|
|
|
Based on the application design and requirement we can assign the orientation and we can customize to make the better look and feel .
Conclusion:
So in this article we have seen the different screen orientations which can be used in the windows phone 7 application development to make a good user experience interface when we tilt the device as per the orientation.