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

查看:23
本文介绍了如何在 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天全站免登陆