locked
Storyboard doesn't show all children animations

    Question

  •    private void SpinButton_Click(object sender, RoutedEventArgs e)
            {
    
                images = CreateImages();
                Storyboard sb = new Storyboard();
    
                for (int i = 0; i < images.Length; i++)
                {
                    sb.Stop();
                    sb.Children.Clear();
                    sb.Children.Add(CreateAnimation(i, 0, 600, images[i]));
                    sb.Begin();
                    
                }
    
            }
    
            private DoubleAnimation CreateAnimation(int delay, double from, double to, DependencyObject image)
            {
                DoubleAnimation myAnimation = new DoubleAnimation();
                myAnimation.SpeedRatio = 8;
                myAnimation.From = from;
                myAnimation.To = to;
                myAnimation.BeginTime = TimeSpan.FromSeconds(1 * delay);
                myAnimation.Duration = new Duration(TimeSpan.FromSeconds(5));
                myAnimation.AutoReverse = false;
    
                Storyboard.SetTarget(myAnimation, image);
                Storyboard.SetTargetProperty(myAnimation, new PropertyPath("(Canvas.Top)"));
    
                return myAnimation;
            }


    Hi everyone

    I have weird problem wih using Storyboard. 

    Check the code at top. After clicking SpinButton only first image is being animated but Storyboard has more than one children...

    Where is the problem that just one image is being animated?

    Tuesday, May 26, 2015 3:22 PM

All replies

  • You're trying to set Canvas.Top from and to the same value on all your pictures at once?

    If it works I would think you'd only see the top image.


    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles

    Tuesday, May 26, 2015 5:12 PM
  • Yes its the idea but as You see I am incrementing delay every image. So thats not the error ;(
    Tuesday, May 26, 2015 7:33 PM
  • Hi Storyboard doesn't show all children animations! (you might want to edit your name to something more name-like :) )

    The Building Windows Store apps with C# or VB forum is retiring!Alert me I'm not sure which forum to move this to though, as it's not clear what exactly you're doing here. Are you writing a Windows Store app? Or is this WPF or Silverlight?

    I wouldn't expect the given animation to run at all in a Windows Store app since Canvas.Top cannot animated independently and you're not setting EnableDependentAnimationin this code.

                            
    Tuesday, May 26, 2015 7:38 PM
    Moderator