How do we disable Portrait mode
of a View in windows 8 ?
Or
For a specific View don't want portrait mode (Rotation of content) .How can prevent this?
I didn't find any useful answer on this topic.Please help.
问问题
1493 次
2 回答
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;
}
}
于 2013-05-29T07:51:49.260 回答
2
在您的应用程序中尝试此方法
http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/82c199a0-57b1-49fe-a706-3e88b8e5148b
如果您必须控制每个页面,那么您需要在页面构造函数中使用这些行后面的代码
Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.Portrait
| Windows.Graphics.Display.DisplayOrientations.PortraitFlipped;
这在模拟器中不起作用,所以请不要混淆:)
于 2013-05-29T12:23:55.547 回答