I have a small project I am working on which is WPF c# that moves an image.
I tried this but doesn’t work
this.NavigationService.Refresh();
I use this method to change the position of the image:
public void Move(Image target, double newX, double newY, Int32 duration)
{
dispatcher.Start();
Vector offset = VisualTreeHelper.GetOffset(target);
var top = offset.Y;
var left = offset.X;
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(0, newY - top, TimeSpan.FromSeconds(duration));
DoubleAnimation anim2 = new DoubleAnimation(0, newX - left, TimeSpan.FromSeconds(duration));
trans.BeginAnimation(TranslateTransform.YProperty, anim1);
trans.BeginAnimation(TranslateTransform.XProperty, anim2);
}
After i move the image, i changed the image’s margin by using:
myImage.Margin = new Thickness(newX, newY, 0, 0)
And what i want now is to add a button that resets all the changes in my program to its default configuration when i first loaded it BUT during runtime. So, the output is when i click the button, the image will go back to its default position.
Even after the animation has ended, it still effects the dependency property. Your choices are
Set the animation’s FillBehavior property to Stop
Remove the entire Storyboard.
Remove the animation from the individual property.
Please look at How to: Set a Property After Animating It with a Storyboard for details