0

I have this code:

public partial class MainWindow : Window
{

    Storyboard st_common = new Storyboard(); 
    DoubleAnimation anim1 = new DoubleAnimation();         

    public MainWindow()
    {
        InitializeComponent();               
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {

        anim1.Duration = new Duration(TimeSpan.FromSeconds(5));
        anim1.From = 10.0;
        anim1.To = 100.0;
        st_common.Children.Add(anim1);
        Storyboard.SetTargetName(anim1, r1.Name);
        Storyboard.SetTargetProperty(anim1, new PropertyPath(Canvas.TopProperty));
        st_common.Begin(this);

    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        r1.SetValue(Canvas.TopProperty, 300.0);            
        r2.SetValue(Canvas.TopProperty, 300.0);
    }
}

Why does SetValue method not work for r1 element after animation? (r1 and r2 are rectangles)

4

1 回答 1

0

The storyboard animation is still holding the value at what the last animated value is. This is a known "feature", and there are three ways around it...

  1. Set the animation FillBehavior to Stop
  2. Remove the storyboard
  3. Remove the entire animation.

See https://msdn.microsoft.com/en-us/library/aa970493%28v=vs.110%29.aspx on how to peform these actions.

于 2015-04-17T15:35:06.990 回答