1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| private CompositionAnimationController controller; private Vector3KeyFrameAnimation _animation; public CompositionAnimationControllerPage() { InitializeComponent(); AnimationSetup(); } private void AnimationSetup() { var compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; var visual = ElementCompositionPreview.GetElementVisual(Rectangle);
int animationDuration = 4; float animationMax = 250f; var linear = compositor.CreateLinearEasingFunction();
_animation = compositor.CreateVector3KeyFrameAnimation(); _animation.InsertKeyFrame(0.25f, new Vector3(animationMax, (float)Canvas.GetTop(Rectangle), 0f), linear); _animation.InsertKeyFrame(0.5f, new Vector3(animationMax, animationMax, 0f), linear); _animation.InsertKeyFrame(0.75f, new Vector3((float)Canvas.GetLeft(Rectangle), animationMax, 0f), linear); _animation.InsertKeyFrame(1f, new Vector3((float)Canvas.GetLeft(Rectangle), (float)Canvas.GetTop(Rectangle), 0f), linear); _animation.Duration = TimeSpan.FromSeconds(animationDuration); _animation.IterationBehavior = AnimationIterationBehavior.Forever;
controller = new CompositionAnimationController(visual, nameof(Visual.Offset), _animation); controller.AttachSlider(slider); controller.PlayIcon = PlayIcon; }
private void PlayPause_Animation(object sender, RoutedEventArgs e) { controller.PlayPause(); } private void Stop_Animation(object sender, RoutedEventArgs e) { controller.Stop();
} private void SpeedUp_Animation(object sender, RoutedEventArgs e) { controller.SpeedUp();
} private void SlowDown_Animation(object sender, RoutedEventArgs e) { controller.SlowDown();
} private void Reverse_Animation(object sender, RoutedEventArgs e) { controller.Reverse(); }
|