ChessBoardVisualLib.ViewModel.SquareItem.AnimateShift C# (CSharp) Method

AnimateShift() public method

public AnimateShift ( double deltaX, double deltaY, Action action ) : void
deltaX double
deltaY double
action Action
return void
        public void AnimateShift(double deltaX, double deltaY, Action<SquareItem> action)
        {
            DoubleAnimation shiftX = new DoubleAnimation();
            shiftX.From = 0;
            shiftX.To = deltaX;
            shiftX.Duration = new Duration(TimeSpan.FromSeconds(0.6));

            DoubleAnimation shiftY = new DoubleAnimation();
            shiftY.From = 0;
            shiftY.To = deltaY;
            shiftY.Duration = shiftX.Duration;

            ParallelTimeline timeline = new ParallelTimeline();
            timeline.Children.Add(shiftX);
            timeline.Children.Add(shiftY);

            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(timeline);

            Storyboard.SetTarget(shiftX, this);
            Storyboard.SetTarget(shiftY, this);

            Storyboard.SetTargetProperty(shiftX, new PropertyPath("DeltaXTransform"));
            Storyboard.SetTargetProperty(shiftY, new PropertyPath("DeltaYTransform"));

            storyboard.Completed += new EventHandler((sender, e) => action(this));

            storyboard.Begin();
        }