There are two properties in your Page.xaml file that control your project's orientation:
SupportedOrientations="Portrait" Orientation="Portrait"
You can set your SupportedOrientations to one of three values:
- Portrait (the default)
- Landscape
- PortraitOrLandscape
The Orientation values is what you want your application to use when it starts:
- Landscape
- LandscapeLeft (tip the phone left)
- LandscapeRight (tip the phone right)
- Portrait
- PortraitDown (normal vertical position)
- PortraitUp (tip the phone upside-down)
Change the appearance of you application when the orientation of your application is changed.
Here’s the code on the 31 Days of Windows Phone | Day #4: Device Orientation the author uses to make the title bar disappear and reappear (this is part of the contents of MainPage.xaml.cs file):
// Constructor
public MainPage()
{
InitializeComponent();
this.OrientationChanged +=
new EventHandler<OrientationChangedEventArgs>(MainPage_OrientationChanged);
}
void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
if ((e.Orientation == PageOrientation.LandscapeRight)
||(e.Orientation == PageOrientation.LandscapeLeft))
{
TitlePanel.Visibility = Visibility.Collapsed;
}
else if ((e.Orientation == PageOrientation.PortraitDown)
|| (e.Orientation == PageOrientation.PortraitUp))
{
TitlePanel.Visibility = Visibility.Visible;
}
}
Because I only care that my application is Landscape or Portrait (and not one of the more specific orientations), I am checking for both states, and adjusting my interface accordingly. You could certainly break out the individual cases seperately, and make your interface look differently for each.
You’ll notice that I created an event handler for the OrientationChanged event. This is certainly the simplest way to recognize when this happens, but you could always use the Accelerometer if you prefer.
No comments:
Post a Comment