5

想要创建一个 Metro 风格的 Windows 8 应用程序,它不会Grid在所有内容处于Portrait模式下旋转根目录。我想在Code和 by中处理方向Visual States,但是现在当我旋转设备时,所有内容都会自动旋转并填充新的宽度和高度。

如何禁用这种旋转行为,即禁用Portrait方向,但仍然能够获取有关方向变化的事件?

另外,Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences似乎不起作用

4

3 回答 3

3

Double click the "Package.appxmanifest" file in your metro app project, you should see configurations of your app. In the "Application UI" page, you can find "Supported rotations" in the middle. 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

    <InitialRotationPreference>
      <Rotation Preference="landscape" />
      <Rotation Preference="portraitFlipped" />
      <Rotation Preference="landscapeFlipped" />
    </InitialRotationPreference>
于 2012-07-21T07:51:47.447 回答
0

抱歉,我错过了您的主要问题。我认为您无法在纵向模式事件之后更改根元素的“旋转”。因为它实际上并没有相对于屏幕旋转,而是屏幕大小发生了变化。

但是,我想您仍然希望用户在纵向模式事件之后以横向模式查看您的应用程序。您可以对抗感知到的旋转。您可以将业务逻辑放在另一个没有预定义大小的用户控件中。将此用户控件放在根页面中。当您收到纵向模式事件时,您将页面 ActualWidth 分配给用户控件高度,将页面 ActualHeight 分配给用户控件宽度,给用户控件一个 90 度的渲染变换和渲染变换中心 x=height*0.707/width, y=0.5,那么用户控件应该与横向模式位置对齐。

于 2012-07-22T07:45:57.427 回答
0

当 Windows 说您处于纵向模式时,将 rotatetransform 添加到您的根元素中,以应对这种情况并保持呈现纵向的内容

于 2012-04-21T22:02:34.977 回答