asitis
asitis

Reputation: 3031

Disable or prevent a Page from Portrait Mode in Windows 8

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.

Upvotes: 3

Views: 1504

Answers (2)

StezPet
StezPet

Reputation: 2450

Try this method in your application

http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/82c199a0-57b1-49fe-a706-3e88b8e5148b

If you have to control this per page then you need to use these lines in Page constructor in code behind

 Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.Portrait
| Windows.Graphics.Display.DisplayOrientations.PortraitFlipped;

This does not work in Simulator so please do not be confused :)

Upvotes: 2

Farhan Ghumra
Farhan Ghumra

Reputation: 15296

If you want to disable your entire app for portrait view, then you can do via app manifest file.

supported rotations

For specific page, there is no built-in support for this, but you could detect the rotation and then apply a transform to rotate it back.

Here's simple demo

<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;
    }
}

Upvotes: 2

Related Questions