• 让你知道手机为什么转动时屏幕会转变(页面的显示切换)Windows Phone 7 平台 X


    打开windows phone 7的开发环境,新建一个project修改主页面的标题和application name,由于暂时无法支持中文,所以都用英语命名,在Mainpage.xaml的页面上新建3个按钮,分别命名为 PortraitPage、LandscapePage、NeutralPage 然后双击button添加Click事件,每个按钮的事件的代码如下:

    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));
    }

    上面代码中显示了三个xaml,所以我们要插入三个xaml 页面名字为ProtraitPage.xaml、 LandscapePage.xaml(注意插入该xaml时选第一个页面类型就是横屏显示的)、NeutralPage.xaml;

    这下在对ProtraitPage.xaml和NeutralPage.xaml进行编码:

    在ProtraitPage.xaml中的public Page1()中的   InitializeComponent();下插入一行

    SupportedOrientations = SupportedPageOrientation.Portrait;

    NeutralPage.xaml:

    public Page3()中的   InitializeComponent();下插入一行

        SupportedOrientations = SupportedPageOrientation.PortraitOrLandscape;
    现在就可以运行了可以看到:
    点Protrait按钮出现的页面还是竖立的;  点Landscape页面变成横的啦; 点Neutral时,手机竖立时页面显示就是竖立的,而如果手机横过来,页面就横过来了;
    --这就是一些手机为什么横过来和竖过来页面会跟着变换
    效果图:

  • 相关阅读:
    CentOS 5.5 系统安全配置
    从PHP5.2.x迁移到PHP5.3.x
    快要放假了!但为什么现在感到特别的累呢?!
    C#、Oracle、Sql server中拼音查询的函数
    C#实现Word中表格信息读取
    用 win2003 架设共享服务器[3]
    用 win2003 架设共享服务器[2]
    用 win2003 架设共享服务器[1]
    c#操作word表格
    Visual Studio 2008(VS2008)升级正式版
  • 原文地址:https://www.cnblogs.com/xspaceworld/p/1776988.html
Copyright © 2020-2023  润新知