FrameworkElement back = GetElement(element);
if (back == null)
return;
PlaneProjection cardProjection;
element.EnsureProjection(out cardProjection);
ScaleTransform cardScale;
TranslateTransform cardTranslate;
RotateTransform cardRotate;
SkewTransform cardSkew;
element.EnsureTransforms(out cardScale, out cardRotate, out cardSkew, out cardTranslate);
ScaleTransform backScale;
TranslateTransform backTranslate;
RotateTransform backRotate;
SkewTransform backSkew;
back.EnsureTransforms(out backScale, out backRotate, out backSkew, out backTranslate);
PlaneProjection backProjection;
back.EnsureProjection(out backProjection);
backProjection.RotationX = -90;
back.Opacity = 0;
back.Visibility = Visibility.Visible;
root.UpdateLayout();
//Position the two animations to meet at the mid. point.
double w = (back.ActualWidth + element.ActualWidth) / 2;
double h = (back.ActualHeight + element.ActualHeight) / 2;
double scaleX = w / element.ActualWidth;
double scaleY = h / element.ActualHeight;
double backScaleX = w / back.ActualWidth;
double backScaleY = h / back.ActualHeight;
Point center = element.TransformToVisual(null).Transform(new Point(element.ActualWidth / 2, element.ActualHeight / 2));
double x = root.ActualWidth / 2 - center.X;
double y = root.ActualHeight / 2 - center.Y;
backScale.ScaleX = backScaleX;
backScale.ScaleY = backScaleY;
backTranslate.X = -x / 2;
backTranslate.Y = -y / 2;
DoubleAnimation mainProjection = AnimationFactory.CreateProjectionXAnimation(cardProjection, 90, Seconds);
DoubleAnimation scaleXAnimation = AnimationFactory.CreateScaleXAnimation(cardScale, scaleX, Seconds);
DoubleAnimation scaleYAnimation = AnimationFactory.CreateScaleYAnimation(cardScale, scaleY, Seconds);
DoubleAnimation translateXAnimation = AnimationFactory.CreateTranslateXAnimation(cardTranslate, cardTranslate.X + x / 2, Seconds);
DoubleAnimation translateYAnimation = AnimationFactory.CreateTranslateYAnimation(cardTranslate, cardTranslate.Y + y / 2, Seconds);
mainProjection.EasingFunction =
translateXAnimation.EasingFunction =
translateYAnimation.EasingFunction =
scaleXAnimation.EasingFunction =
scaleYAnimation.EasingFunction =
new QuadraticEase
{
EasingMode = EasingMode.EaseIn
};
DoubleAnimation backProjectionAnimation = AnimationFactory.CreateProjectionXAnimation(backProjection, 0, Seconds);
DoubleAnimation backScaleXAnimation = AnimationFactory.CreateScaleXAnimation(backScale, 1, Seconds);
DoubleAnimation backScaleYAnimation = AnimationFactory.CreateScaleYAnimation(backScale, 1, Seconds);
DoubleAnimation backTranslateXAnimation = AnimationFactory.CreateTranslateXAnimation(backTranslate, 0, Seconds);
DoubleAnimation backTranslateYAnimation = AnimationFactory.CreateTranslateYAnimation(backTranslate, 0, Seconds);
var backOpacityAnimation = new ObjectAnimationUsingKeyFrames();
backOpacityAnimation.KeyFrames.Add(new DiscreteObjectKeyFrame
{
KeyTime = TimeSpan.FromSeconds(0),
Value = 1
});
Storyboard.SetTarget(backOpacityAnimation, back);
Storyboard.SetTargetProperty(backOpacityAnimation, new PropertyPath("Opacity"));
backProjectionAnimation.BeginTime =
backScaleXAnimation.BeginTime =
backScaleYAnimation.BeginTime =
backTranslateXAnimation.BeginTime =
backTranslateYAnimation.BeginTime =
backOpacityAnimation.BeginTime =
TimeSpan.FromSeconds(Seconds);
backProjectionAnimation.EasingFunction =
backScaleXAnimation.EasingFunction =
backScaleYAnimation.EasingFunction =
backTranslateXAnimation.EasingFunction =
backTranslateYAnimation.EasingFunction =
new QuadraticEase
{
EasingMode = EasingMode.EaseOut
};
var flipping = new Storyboard();
flipping.Children.Add(mainProjection);
flipping.Children.Add(scaleXAnimation);
flipping.Children.Add(scaleYAnimation);
flipping.Children.Add(translateXAnimation);
flipping.Children.Add(translateYAnimation);
flipping.Children.Add(backOpacityAnimation);
flipping.Children.Add(backProjectionAnimation);
flipping.Children.Add(backScaleXAnimation);
flipping.Children.Add(backScaleYAnimation);
flipping.Children.Add(backTranslateXAnimation);
flipping.Children.Add(backTranslateYAnimation);
flipping.Completed += (s, e1) =>
{
element.Visibility = Visibility.Collapsed;
};
flipping.Begin();