public override void OnApplyTemplate() { base.OnApplyTemplate(); this.AddHandler(MouseDownEvent, new RoutedEventHandler((sender, e) => { var targetHeight = Math.Max(ActualWidth, ActualHeight) * 2; var mousePosition = (e as MouseButtonEventArgs).GetPosition(this); var startMargin = new Thickness(mousePosition.X, mousePosition.Y, 0, 0); var animation = GridContainer.FindResource("EllipseAnimation") as Storyboard; //set initial margin to mouse position Ellipse.Margin = startMargin; //set the to value of the animation that animates the width to the target width (animation.Children[0] as DoubleAnimation).To = targetHeight; //set the to and from values of the animation that animates the distance relative to the container (grid) (animation.Children[1] as ThicknessAnimation).From = startMargin; (animation.Children[1] as ThicknessAnimation).To = new Thickness(mousePosition.X - targetHeight / 2, mousePosition.Y - targetHeight / 2, 0, 0); Ellipse.BeginStoryboard(animation); }), true); }