2011-11-11 87 views
2

我有一个小项目,我正在研究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) 

而我现在想要的是添加一个按钮,将我的程序中的所有更改重置为当我第一次加载时它的默认配置,但在运行时。所以,输出是当我点击按钮时,图像将回到其默认位置。

回答

0

即使动画结束后,它仍然会影响依赖项属性。您的选择是

  • 设置动画的FillBehavior物业停止

  • 删除整个故事板。

  • 从各个属性中删除动画。

请看How to: Set a Property After Animating It with a Storyboard的细节

+0

你能给我如何使用FillBehavior一个示例代码段? –