<Page
    x:Class="TapToFlip.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TapToFlip"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    
    <Page.Resources>
        <Storyboard x:Key="flipStoryboard">
            <DoubleAnimationUsingKeyFrames
                             Storyboard.TargetName="projection"
                             Storyboard.TargetProperty="RotationY">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                <LinearDoubleKeyFrame KeyTime="0:0:0.99" Value="90" />
                <DiscreteDoubleKeyFrame KeyTime="0:0:1.01" Value="-90" />
                <LinearDoubleKeyFrame KeyTime="0:0:2" Value="0" />
            </DoubleAnimationUsingKeyFrames>
            
            <DoubleAnimation Storyboard.TargetName="projection"
                             Storyboard.TargetProperty="GlobalOffsetZ"
                             From="0" To="-1000" Duration="0:0:1"
                             AutoReverse="True" />

            <ObjectAnimationUsingKeyFrames
                             Storyboard.TargetName="grid1"
                             Storyboard.TargetProperty="(Canvas.ZIndex)">
                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="1" />
                <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="0" />
            </ObjectAnimationUsingKeyFrames>
            
            <ObjectAnimationUsingKeyFrames
                             Storyboard.TargetName="grid2"
                             Storyboard.TargetProperty="(Canvas.ZIndex)">
                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0" />
                <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="1" />
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        
        <Storyboard x:Key="flipBackStoryboard">
            <DoubleAnimationUsingKeyFrames
                             Storyboard.TargetName="projection"
                             Storyboard.TargetProperty="RotationY">
                <DiscreteDoubleKeyFrame KeyTime="0:0:0" Value="0" />
                <LinearDoubleKeyFrame KeyTime="0:0:0.99" Value="-90" />
                <DiscreteDoubleKeyFrame KeyTime="0:0:1.01" Value="90" />
                <LinearDoubleKeyFrame KeyTime="0:0:2" Value="0" />
            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimation Storyboard.TargetName="projection"
                             Storyboard.TargetProperty="GlobalOffsetZ"
                             From="0" To="-1000" Duration="0:0:1"
                             AutoReverse="True" />

            <ObjectAnimationUsingKeyFrames
                             Storyboard.TargetName="grid1"
                             Storyboard.TargetProperty="(Canvas.ZIndex)">
                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="0" />
                <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="1" />
            </ObjectAnimationUsingKeyFrames>

            <ObjectAnimationUsingKeyFrames
                             Storyboard.TargetName="grid2"
                             Storyboard.TargetProperty="(Canvas.ZIndex)">
                <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="1" />
                <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="0" />
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
    </Page.Resources>

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid HorizontalAlignment="Center"
              VerticalAlignment="Center"
              Tapped="OnGridTapped">
           
            <Grid Name="grid1"
                  Background="Cyan"
                  Canvas.ZIndex="1">
                <TextBlock Text="Hello"
                           HorizontalAlignment="Center"
                           FontSize="192" />
            </Grid>
            
            <Grid Name="grid2"
                  Background="Yellow"
                  Canvas.ZIndex="0">
                <TextBlock Text="Windows 8"
                           FontSize="192" />
            </Grid>
            
            <Grid.Projection>
                <PlaneProjection x:Name="projection" />
            </Grid.Projection>
        </Grid>
    </Grid>
</Page>
