简体   繁体   English

在Windows 8中处理方向

[英]Handle orientations in Windows 8

A want to create an Metro Style Windows 8 application that doesn't rotate a root Grid with all content in Portrait mode. 想要创建一个Metro Style Windows 8应用程序,该应用程序不会在Portrait模式下旋转所有内容的根Grid I want to handle orientation in Code and by Visual States , but now when I rotate device, all content is automatically rotates and fill new width and height. 我想在CodeVisual States处理方向,但现在当我旋转设备时,所有内容都会自动旋转并填充新的宽度和高度。

How can I disable this rotation behavior, ie disable Portrait orientation, but is still be able to get events about orientation changes? 如何禁用此旋转行为,即禁用Portrait方向,但仍能够获取有关方向更改的事件?

Also, Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences doesn't seems to work 此外, Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences似乎不起作用

Double click the "Package.appxmanifest" file in your metro app project, you should see configurations of your app. 双击metro应用程序项目中的“Package.appxmanifest”文件,您应该会看到应用程序的配置。 In the "Application UI" page, you can find "Supported rotations" in the middle. 在“应用程序UI”页面中,您可以在中间找到“支持的旋转”。 You can check the mode you supported, and leave the "Portrait" mode unchecked. 您可以检查支持的模式,并取消选中“纵向”模式。 Then you app will not receive any "portrait" mode events anymore. 然后你的应用程序将不再接收任何“肖像”模式事件。

If you write your own appx manifiest, you can add following block under section, like this 如果你编写自己的appx最明显,你可以添加以下块,如下所示

    <InitialRotationPreference>
      <Rotation Preference="landscape" />
      <Rotation Preference="portraitFlipped" />
      <Rotation Preference="landscapeFlipped" />
    </InitialRotationPreference>

当Windows表示您处于纵向模式时,请向您的根元素添加一个rotatetransform,以对抗该元素,并使事物呈现为纵向

Sorry I missed your primary question. 抱歉,我错过了你的主要问题。 I don't think you can change the "rotation" of the root element after the portrait mode event. 我不认为你可以在肖像模式事件后更改根元素的“旋转”。 Because its actually not rotated relative to the screen, but screen size is changed. 因为它实际上没有相对于屏幕旋转,但屏幕尺寸发生了变化。

However, I suppose you still want the user to look at your app in landscape mode after the portrait mode event. 但是,我想您仍然希望用户在纵向模式事件后以横向模式查看您的应用程序。 You can counter the perceived rotation. 你可以对抗感知的旋转。 You can put you business logic in another user control with no predefined size. 您可以将业务逻辑放在另一个没有预定义大小的用户控件中。 Put this user control in the root page. 将此用户控件放在根页面中。 When you received the portrait mode event, you assign page ActualWidth to user control height, page ActualHeight to user control Width, the give user control a render transform of 90 degrees and render transform center x=height*0.707/width, y=0.5, then user control should just align to the landscape mode position. 当您收到纵向模式事件时,将页面ActualWidth分配给用户控制高度,将ActualHeight页面指定给用户控件宽度,给予用户控件90度渲染变换并渲染变换中心x =高度* 0.707 /宽度,y = 0.5,然后用户控件应该只对齐横向模式位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM