我们如何在Windows 8中禁用View的Portrait mode
?
或者
对于特定的视图,不要想要纵向模式(旋转内容)。如何防止这种情况?
关于这个话题,我没有找到任何有用的答案。请帮助。
答案 0 :(得分:2)
如果要禁用纵向视图的整个应用程序,则可以通过应用程序清单文件进行操作。
对于特定页面,没有内置支持,但您可以检测旋转,然后应用变换将其旋转回来。
这是一个简单的演示
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}" SizeChanged="Grid_SizeChanged_1">
<Canvas>
<Grid x:Name="baseGrid" RenderTransformOrigin="0.5,0.5" Background="Aqua">
<Grid.RenderTransform>
<CompositeTransform x:Name="baseGridRotateTransform" />
</Grid.RenderTransform>
<TextBlock Text="Hello World!" FontSize="50" HorizontalAlignment="Center" VerticalAlignment="Center" />
<TextBlock Text="Hello World!" FontSize="50" Margin="914,354,-914,-354" />
<TextBlock Text="Hello World!" FontSize="50" Margin="112,354,-280,-354" />
</Grid>
</Canvas>
</Grid>
private void Grid_SizeChanged_1(object sender, SizeChangedEventArgs e)
{
if (Windows.UI.ViewManagement.ApplicationView.Value == Windows.UI.ViewManagement.ApplicationViewState.FullScreenPortrait)
{
baseGrid.Width = Window.Current.Bounds.Height;
baseGrid.Height = Window.Current.Bounds.Width;
baseGridRotateTransform.Rotation = 90;
baseGridRotateTransform.TranslateX = -(Window.Current.Bounds.Height - Window.Current.Bounds.Width) / 2;
baseGridRotateTransform.TranslateY = (Window.Current.Bounds.Height - Window.Current.Bounds.Width) / 2;
}
else
{
baseGridRotateTransform.Rotation = 0;
baseGridRotateTransform.TranslateX = 0;
baseGridRotateTransform.TranslateY = 0;
baseGrid.Height = Window.Current.Bounds.Height;
baseGrid.Width = Window.Current.Bounds.Width;
}
}
答案 1 :(得分:2)
在您的应用程序中尝试此方法
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/82c199a0-57b1-49fe-a706-3e88b8e5148b
如果你必须每页控制一次,那么你需要在后面的代码中使用Page构造函数中的这些行
Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.Portrait
| Windows.Graphics.Display.DisplayOrientations.PortraitFlipped;
这在模拟器中不起作用所以请不要混淆:)