Try to add RenderTransformOrigin
and initialize a new instance of the ScaleTransform class for MainImage. The below is my updated code for your:
//Add below two lines code
MainImage.RenderTransform = new ScaleTransform();
MainImage.RenderTransformOrigin = new Point(0.5, 0.5);
Storyboard sb = new Storyboard();
DoubleAnimation ScaleAnimation = new DoubleAnimation();
ScaleAnimation.Duration = TimeSpan.FromMilliseconds(milliseconds);
ScaleAnimation.DecelerationRatio = 0.9f;
ScaleAnimation.From = 1.0;
ScaleAnimation.To = 10.0;
Storyboard.SetTarget(ScaleAnimation, MainImage);
Storyboard.SetTargetProperty(ScaleAnimation, new PropertyPath("RenderTransform.(ScaleTransform.ScaleX)"));
sb.Children.Add(ScaleAnimation);
sb.Begin();
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.