Open the development environment of Windows Phone 7 and create a new project to modify the title and Application name of the home page. Because Chinese characters are not supported for the time being, they are all named in English. create three buttons on the XAML page, named portraitpage, landscapepage, and neutralpage respectively, and double-click the button to add a click event. The code for each button event is as follows:
private void onPortraitPage(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/PortraitPage.xaml", UriKind.Relative));
}
private void onLandscapePage(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/LandscapePage.xaml", UriKind.Relative));
}
private void onNeutralPage(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/NeutralPage.xaml", UriKind.Relative));
}
The code above shows three XAML, so we need to insert three XAML pages named protraitpage. XAML, landscapepage. XAML (note that when this XAML is inserted, the first page type is displayed on a horizontal screen) and neutralpage. XAML;
Encode protraitpage. XAML and neutralpage. XAML:
Insert a row under initializecomponent (); in public page1 () in protraitpage. XAML
SupportedOrientations = SupportedPageOrientation.Portrait;
Neutralpage. XAML:
Initializecomponent (); in public page3 (), insert a row
SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
Now you can run it. You can see:
The page displayed by clicking the protrait button is still erected; the landscape page is changed to a horizontal one; when clicking the neutral button, the page is displayed as a portrait when the mobile phone is portrait, and if the mobile phone is crossed, the page is crossed;
-- That's why some mobile phones are switching from horizontal to vertical pages.
: