Question

I am developing an application for windows phone.

It has a video player.

Now, I want to change the UI when the phone orientation changes. The video player should take the full screen.

But the problem is, when the UI changes I don't want the video player to pause or stop or load again.

So, inside the content panel, I made 2 grids.

I thought I would hide one grid completely and move the video player to the other grid. This other grid would be the only thing visible on the screen - so it would be full screen.

But the video player is inside a pivot.

Here is the xaml-

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        <Grid Name="VideoPlayerGrid" >
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            //I want my video player here - this should make it full screen
        </Grid>

        <Grid Name="ContentGrid"> //I would hide this grid completely

            <phone:Pivot Name="Pivot1">
                <phone:PivotItem Header="PivotItem1">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        // my video player is here

                    </Grid>
                </phone:PivotItem>

                <phone:PivotItem Header="PivotItem2">

                </phone:PivotItem>
            </phone:Pivot>

How can I handle the orientation change?

Was it helpful?

Solution

First,add OrientationChanged="PhoneApplicationPage_OrientationChanged" in your page of xaml

Then handle it in your code-behind:

private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
    if (e.Orientation == PageOrientation.Landscape ||
        e.Orientation == PageOrientation.LandscapeLeft ||
        e.Orientation == PageOrientation.LandscapeRight)
        {
           // do something            
        }
        else
        {
           // do something            
        }
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top