RotationHorizontalTileAnimation.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using Windows.UI.Xaml;
  3. using Windows.UI.Xaml.Media.Animation;
  4. namespace FormulaOneApp.Classic.Windows.Controls.Tile.Animations
  5. {
  6. public class RotationHorizontalTileAnimation : ITileAnimation
  7. {
  8. public Storyboard GetStoryboard(Tile tile)
  9. {
  10. var animDuration = new Duration(TimeSpan.FromMilliseconds(1000d));
  11. var storyboard = new Storyboard();
  12. var animationSnapFront = new DoubleAnimation
  13. {
  14. EnableDependentAnimation = true,
  15. From = 0,
  16. To = 180,
  17. Duration = animDuration,
  18. EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut, Exponent = 8d }
  19. };
  20. var animationSnapFrontOpacity = new DoubleAnimation
  21. {
  22. EnableDependentAnimation = true,
  23. From = 1,
  24. To = 0,
  25. BeginTime = TimeSpan.FromMilliseconds(50d),
  26. Duration = new Duration(TimeSpan.FromMilliseconds(1d))
  27. };
  28. storyboard.Children.Add(animationSnapFront);
  29. storyboard.Children.Add(animationSnapFrontOpacity);
  30. Storyboard.SetTarget(animationSnapFront, tile.IsFrontSide ? tile.FrontContentPresenter : tile.BackContentPresenter);
  31. Storyboard.SetTargetProperty(animationSnapFront, "(UIElement.Projection).(PlaneProjection.RotationY)");
  32. Storyboard.SetTarget(animationSnapFrontOpacity, tile.IsFrontSide ? tile.FrontContentPresenter : tile.BackContentPresenter);
  33. Storyboard.SetTargetProperty(animationSnapFrontOpacity, "Opacity");
  34. var animationSnapBack = new DoubleAnimation
  35. {
  36. EnableDependentAnimation = true,
  37. From = 180,
  38. To = 0,
  39. Duration = animDuration,
  40. EasingFunction = new ExponentialEase { EasingMode = EasingMode.EaseOut, Exponent = 8d }
  41. };
  42. var animationSnapBackOpacity = new DoubleAnimation
  43. {
  44. EnableDependentAnimation = true,
  45. From = 0,
  46. To = 1,
  47. BeginTime = TimeSpan.FromMilliseconds(50d),
  48. Duration = new Duration(TimeSpan.FromMilliseconds(1d))
  49. };
  50. storyboard.Children.Add(animationSnapBack);
  51. storyboard.Children.Add(animationSnapBackOpacity);
  52. Storyboard.SetTarget(animationSnapBack, !tile.IsFrontSide ? tile.FrontContentPresenter : tile.BackContentPresenter);
  53. Storyboard.SetTargetProperty(animationSnapBack, "(UIElement.Projection).(PlaneProjection.RotationY)");
  54. Storyboard.SetTarget(animationSnapBackOpacity, !tile.IsFrontSide ? tile.FrontContentPresenter : tile.BackContentPresenter);
  55. Storyboard.SetTargetProperty(animationSnapBackOpacity, "Opacity");
  56. tile.IsFrontSide = !tile.IsFrontSide;
  57. return storyboard;
  58. }
  59. }
  60. }