|
| 1 | +<UserControl x:Class="WpfPageTransitions.PageTransition" |
| 2 | + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
| 3 | + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
| 4 | + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
| 5 | + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
| 6 | + xmlns:local="clr-namespace:WpfPageTransitions" |
| 7 | + mc:Ignorable="d" |
| 8 | + d:DesignHeight="300" d:DesignWidth="300"> |
| 9 | + <UserControl.Resources> |
| 10 | + |
| 11 | + <Style TargetType="{x:Type ContentPresenter}"> |
| 12 | + <Setter Property="LayoutTransform"> |
| 13 | + <Setter.Value> |
| 14 | + <ScaleTransform /> |
| 15 | + </Setter.Value> |
| 16 | + </Setter> |
| 17 | + </Style> |
| 18 | + |
| 19 | + <local:CenterConverter x:Key="centerConverter"/> |
| 20 | + |
| 21 | + <!-- Slide and Fade --> |
| 22 | + <Storyboard x:Key="SlideAndFadeIn" > |
| 23 | + <ThicknessAnimation Duration="0:0:.75" Storyboard.TargetProperty="Margin" From="500,0,-500,0" To="0" DecelerationRatio=".9" /> |
| 24 | + <DoubleAnimation Duration="0:0:.25" Storyboard.TargetProperty="Opacity" From="0" To="1" /> |
| 25 | + </Storyboard> |
| 26 | + |
| 27 | + <Storyboard x:Key="SlideAndFadeOut"> |
| 28 | + <ThicknessAnimation Duration="0:0:.5" Storyboard.TargetProperty="Margin" To="-500,0,500,0" AccelerationRatio=".9"/> |
| 29 | + <DoubleAnimation Duration="0:0:.25" Storyboard.TargetProperty="Opacity" To="0" /> |
| 30 | + </Storyboard> |
| 31 | + |
| 32 | + <!-- Fade --> |
| 33 | + <Storyboard x:Key="FadeIn" > |
| 34 | + <DoubleAnimation Duration="0:0:.2" Storyboard.TargetProperty="Opacity" From="0" To="1" /> |
| 35 | + </Storyboard> |
| 36 | + |
| 37 | + <Storyboard x:Key="FadeOut"> |
| 38 | + <DoubleAnimation Duration="0:0:.2" Storyboard.TargetProperty="Opacity" To="0" /> |
| 39 | + </Storyboard> |
| 40 | + |
| 41 | + <!-- Slide --> |
| 42 | + <Storyboard x:Key="SlideIn" > |
| 43 | + <ThicknessAnimation Duration="0:0:.75" Storyboard.TargetProperty="Margin" From="500,0,-500,0" To="0" DecelerationRatio=".9" /> |
| 44 | + </Storyboard> |
| 45 | + |
| 46 | + <Storyboard x:Key="SlideOut"> |
| 47 | + <ThicknessAnimation Duration="0:0:.5" Storyboard.TargetProperty="Margin" To="-500,0,500,0" AccelerationRatio=".9"/> |
| 48 | + </Storyboard> |
| 49 | + |
| 50 | + <!-- Grow --> |
| 51 | + <Storyboard x:Key="GrowIn" > |
| 52 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" From="0" To="1" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 53 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" From="0" To="1" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 54 | + </Storyboard> |
| 55 | + |
| 56 | + <Storyboard x:Key="GrowOut"> |
| 57 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" To="0" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 58 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" To="0" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 59 | + </Storyboard> |
| 60 | + |
| 61 | + <!-- Grow and Fade --> |
| 62 | + <Storyboard x:Key="GrowAndFadeIn" > |
| 63 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" From="0" To="1" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 64 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" From="0" To="1" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 65 | + <DoubleAnimation Duration="0:0:.25" Storyboard.TargetProperty="Opacity" From="0" To="1" /> |
| 66 | + </Storyboard> |
| 67 | + |
| 68 | + <Storyboard x:Key="GrowAndFadeOut"> |
| 69 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" To="0" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 70 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" To="0" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 71 | + <DoubleAnimation Duration="0:0:.75" Storyboard.TargetProperty="Opacity" To="0" /> |
| 72 | + </Storyboard> |
| 73 | + |
| 74 | + <!-- Flip --> |
| 75 | + <Storyboard x:Key="FlipIn" > |
| 76 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)" From="-100" To="0" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 77 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleY)" From="-100" To="0" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 78 | + </Storyboard> |
| 79 | + |
| 80 | + <Storyboard x:Key="FlipOut"> |
| 81 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)" To="100" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 82 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleY)" To="100" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 83 | + </Storyboard> |
| 84 | + |
| 85 | + <!-- Flip and Fade --> |
| 86 | + <Storyboard x:Key="FlipAndFadeIn" > |
| 87 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)" From="-100" To="0" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 88 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleY)" From="-100" To="0" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 89 | + <DoubleAnimation Duration="0:0:.25" Storyboard.TargetProperty="Opacity" From="0" To="1" /> |
| 90 | + </Storyboard> |
| 91 | + |
| 92 | + <Storyboard x:Key="FlipAndFadeOut"> |
| 93 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)" To="100" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 94 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleY)" To="100" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 95 | + <DoubleAnimation Duration="0:0:.75" Storyboard.TargetProperty="Opacity" To="0" /> |
| 96 | + </Storyboard> |
| 97 | + |
| 98 | + <!-- Spin --> |
| 99 | + <Storyboard x:Key="SpinIn" > |
| 100 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" From="-360" To="0" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 101 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" From="0" To="1" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 102 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" From="0" To="1" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 103 | + </Storyboard> |
| 104 | + |
| 105 | + <Storyboard x:Key="SpinOut"> |
| 106 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" To="360" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 107 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" To="0" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 108 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" To="0" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 109 | + </Storyboard> |
| 110 | + |
| 111 | + <!-- Spin and Fade --> |
| 112 | + <Storyboard x:Key="SpinAndFadeIn" > |
| 113 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" From="-360" To="0" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 114 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" From="0" To="1" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 115 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" From="0" To="1" Duration="0:0:.75" DecelerationRatio=".9" /> |
| 116 | + <DoubleAnimation Duration="0:0:.25" Storyboard.TargetProperty="Opacity" From="0" To="1" /> |
| 117 | + </Storyboard> |
| 118 | + |
| 119 | + <Storyboard x:Key="SpinAndFadeOut"> |
| 120 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" To="360" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 121 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" To="0" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 122 | + <DoubleAnimation Storyboard.TargetProperty="(RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" To="0" Duration="0:0:.75" AccelerationRatio=".9" /> |
| 123 | + <DoubleAnimation Duration="0:0:.75" Storyboard.TargetProperty="Opacity" To="0" /> |
| 124 | + </Storyboard> |
| 125 | + |
| 126 | + </UserControl.Resources> |
| 127 | + |
| 128 | + <Grid Name="page"> |
| 129 | + |
| 130 | + <ContentControl Name="contentPresenter"> |
| 131 | + <ContentControl.RenderTransform> |
| 132 | + <TransformGroup> |
| 133 | + <ScaleTransform ScaleX="1" ScaleY="1" |
| 134 | + CenterX="{Binding RelativeSource={RelativeSource AncestorType=Grid, Mode=FindAncestor}, Path=ActualWidth, Converter={StaticResource centerConverter}}" |
| 135 | + CenterY="{Binding RelativeSource={RelativeSource AncestorType=Grid, Mode=FindAncestor}, Path=ActualHeight, Converter={StaticResource centerConverter}}" /> |
| 136 | + <SkewTransform AngleX="0" AngleY="0" |
| 137 | + CenterX="{Binding RelativeSource={RelativeSource AncestorType=Grid, Mode=FindAncestor}, Path=ActualWidth, Converter={StaticResource centerConverter}}" |
| 138 | + CenterY="{Binding RelativeSource={RelativeSource AncestorType=Grid, Mode=FindAncestor}, Path=ActualHeight, Converter={StaticResource centerConverter}}" /> |
| 139 | + <RotateTransform Angle="0" |
| 140 | + CenterX="{Binding RelativeSource={RelativeSource AncestorType=Grid, Mode=FindAncestor}, Path=ActualWidth, Converter={StaticResource centerConverter}}" |
| 141 | + CenterY="{Binding RelativeSource={RelativeSource AncestorType=Grid, Mode=FindAncestor}, Path=ActualHeight, Converter={StaticResource centerConverter}}" /> |
| 142 | + <TranslateTransform X="0" Y="0" /> |
| 143 | + </TransformGroup> |
| 144 | + </ContentControl.RenderTransform> |
| 145 | + </ContentControl> |
| 146 | + |
| 147 | + </Grid> |
| 148 | + |
| 149 | +</UserControl> |
0 commit comments