internal void ExecuteThen() { if (_action1 != null) { _action1(); } else if (_action2 != null) { _action2(_element); } if (_shouldClearAnimation) { _transform.ApplyAnimationClock(TranslateTransform.XProperty, null); _transform.ApplyAnimationClock(TranslateTransform.YProperty, null); } }
// When the user left-clicks, use the // SnapshotAndReplace HandoffBehavior when applying the animation. private void border_mouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Point clickPoint = Mouse.GetPosition(containerBorder); // Set the target point so the center of the ellipse // ends up at the clicked point. Point targetPoint = new Point(); targetPoint.X = clickPoint.X - interactiveEllipse.Width / 2; targetPoint.Y = clickPoint.Y - interactiveEllipse.Height / 2; // Animate to the target point. DoubleAnimation xAnimation = new DoubleAnimation(targetPoint.X, new Duration(TimeSpan.FromSeconds(4))); AnimationClock xAnimationClock = xAnimation.CreateClock(); interactiveTranslateTransform.ApplyAnimationClock( TranslateTransform.XProperty, xAnimationClock, HandoffBehavior.SnapshotAndReplace); DoubleAnimation yAnimation = new DoubleAnimation(targetPoint.Y, new Duration(TimeSpan.FromSeconds(4))); AnimationClock yAnimationClock = yAnimation.CreateClock(); interactiveTranslateTransform.ApplyAnimationClock( TranslateTransform.YProperty, yAnimationClock, HandoffBehavior.SnapshotAndReplace); // Change the color of the ellipse. interactiveEllipse.Fill = Brushes.Lime; }