我有一个正在处理的小项目,是移动图像的WPF c#。
我试过了但是没用
this.NavigationService.Refresh();
我使用这种方法来更改图像的位置:
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);
}
移动图像后,我使用以下方法更改了图像的边距:
myImage.Margin = new Thickness(newX, newY, 0, 0)
现在,我想要添加一个按钮,当我在运行时首次将其加载时,将程序中的所有更改重置为其默认配置。因此,输出是当我单击按钮时,图像将返回其默认位置。
最佳答案
即使动画结束后,它仍然会影响依赖项属性。您的选择是
将动画的FillBehavior属性设置为Stop
删除整个情节提要。
从单个属性中删除动画。
请查看How to: Set a Property After Animating It with a Storyboard了解详细信息