RectNavigation.Animate.MoveWithRotationAndFadeOut C# (CSharp) Method

MoveWithRotationAndFadeOut() public static method

public static MoveWithRotationAndFadeOut ( FrameworkElement element, Point to, double rotationAngle, double seconds, AnimationCompletedDelegate callback ) : void
element System.Windows.FrameworkElement
to Point
rotationAngle double
seconds double
callback AnimationCompletedDelegate
return void
        public static void MoveWithRotationAndFadeOut(FrameworkElement element, Point to, double rotationAngle, double seconds, AnimationCompletedDelegate callback)
        {
            TransformGroup transformGroup = new TransformGroup();
            transformGroup.Children.Add(new RotateTransform(rotationAngle, element.Width / 2, element.Height / 2));

            Duration duration = new Duration(TimeSpan.FromSeconds(seconds));
            DoubleAnimation animationX = new DoubleAnimation(to.X, duration);
            DoubleAnimation animationY = new DoubleAnimation(to.Y, duration);
            DoubleAnimation fadeOutAnimation = new DoubleAnimation
            {
                From = 1,
                To = 0.4,
                Duration = duration,
                FillBehavior = FillBehavior.Stop
            };

            animationX.Completed += (sender, _) => callback(sender, _);

            TranslateTransform trans = new TranslateTransform();
            element.RenderTransform = transformGroup;

            trans.BeginAnimation(TranslateTransform.XProperty, animationX);
            trans.BeginAnimation(TranslateTransform.YProperty, animationY);

            element.Opacity = 0.4;
            element.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation);
            transformGroup.Children.Add(trans);
        }

Usage Example

        /// <summary>
        /// Animates the Pointer Arrow from the right hand to the rectangle
        /// </summary>
        public void AnimatePointerArrow()
        {
            if (!pointerAnimationRunning)
            {
                pointerAnimationRunning = true;

                Canvas.SetLeft(PointerArrow, _handPoint.X - (PointerArrow.Width / 2));
                Canvas.SetTop(PointerArrow, _handPoint.Y - (PointerArrow.Height / 2));

                Point innerRectMiddlePoint = new Point(_innerRect.Left + (_innerRect.Width / 2),
                                                       _innerRect.Top + (_innerRect.Height / 2));

                Vector handToRectVector = new Vector(innerRectMiddlePoint.X - _handPoint.X, innerRectMiddlePoint.Y - _handPoint.Y);

                // new Vector ist der Vektor von Handposition auf selber ebene nach links
                double rotateAngle = getRotateAngle(handToRectVector, new Vector(-10, 0));

                // Drehrichtung des Pfeiles in Oberen Haelfte umdrehen
                if (_handPoint.Y < innerRectMiddlePoint.Y)
                {
                    rotateAngle = -rotateAngle;
                }

                double duration = 1.3;
                Animate.MoveWithRotationAndFadeOut(PointerArrow, new Point(handToRectVector.X, handToRectVector.Y), rotateAngle, duration, ArrowAnimationCompleted);
            }
        }