Skip to content

Instantly share code, notes, and snippets.

@colinkiama
Last active December 23, 2020 11:51
Show Gist options
  • Save colinkiama/eb1cbf641fb61e5cfc729819873abe6f to your computer and use it in GitHub Desktop.
Save colinkiama/eb1cbf641fb61e5cfc729819873abe6f to your computer and use it in GitHub Desktop.
UWP endless rotation animation with Windows.UI.Composition
Vector3 centerPoint = new Vector3((float)(element.ActualWidth * 0.5),
(float)(element.ActualHeight * 0.5), 0);
Visual logoDropShadowVisual = ElementCompositionPreview.GetElementVisual(element);
Compositor compositor = logoDropShadowVisual.Compositor;
ScalarKeyFrameAnimation animation = compositor.CreateScalarKeyFrameAnimation();
// Ensures that visual rotates at a consistent rate.
LinearEasingFunction easing = compositor.CreateLinearEasingFunction();
animation.InsertKeyFrame(1f, 360f, easing);
animation.Duration = TimeSpan.FromSeconds(5);
animation.IterationBehavior = AnimationIterationBehavior.Forever;
logoDropShadowVisual.CenterPoint = centerPoint;
logoDropShadowVisual.StartAnimation("RotationAngleInDegrees", animation);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment