如何在UWP应用中仅启用横向模式? [英] How to enable only landscape mode in a UWP app?

查看:67
本文介绍了如何在UWP应用中仅启用横向模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在清单中将其指定为Landscape和LandscapeFlipped,我知道这只是一个首选项,此外,我还在App.xaml.cs OnLaunched中添加了以下代码。但是,当在平板电脑上进行测试时,该应用将返回纵向模式。

I have already specified in the manifest as Landscape and LandscapeFlipped, I know this is just a preference and on top of this I've added the below code in the App.xaml.cs OnLaunched. But yet when tested on a tablet the app goes back to portrait mode.

 DisplayInformation.AutoRotationPreferences = 
                     DisplayOrientations.Landscape | DisplayOrientations.LandscapeFlipped;

还有什么其他方法可以在模拟器中而不是实际的平板电脑/设备上进行测试吗?

Also is there any alternative way I could test this in a simulator instead of an actual tablet/device?

预先感谢。

推荐答案

由于我的评论对您有所帮助将其添加为答案

Since my comment helped you im going to add it as answer

参考

解决方案

[DllImport("user32.dll", EntryPoint = "#2507")]
extern static bool SetAutoRotation(bool bEnable);

SetAutoRotation(false);

这篇关于如何在UWP应用中仅启用横向模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆