且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

[UWP] [C#]在平板电脑和手机上设置特定方向

更新时间:2023-02-27 08:11:21

Hello。

Hello.

Util WP8.1有PhoneApplicationPage控件的SupportedOrientations属性。但在UWP中并不存在这样的财产。为了实现你想要的你应该改变 

Util WP8.1 there was SupportedOrientations property for PhoneApplicationPage control. But in UWP there doesnn't exist such property. For achieve what you want you should change 

DisplayInformation.AutoRotationPreferences


 protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            switch (AnalyticsInfo.VersionInfo.DeviceFamily)
            {
                case "Windows.Mobile":
                    DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;
                    break;
                case "Windows.Desktop":
                    DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
                    break;
            }
        }