0

Hi I am currently trying to create a sequence of animations using a single storyboard. I have it working however, the two animations in this storyboard don't seem to follow the begin time or duration ive set. They run over each other resulting in part of the animation being hidden.

From my testing its only the DoubleAnimation which doesnt seem to end when it should as will continue to stay active until the entire duration of the storyboard is finished.

Below is the code i have.

private void SetUpAnimation()
        {
            animation1 = new DoubleAnimation
            {
                From = 0.0,
                To = 1.0,
                Duration = new Duration(TimeSpan.FromSeconds(2.0)),
                BeginTime = TimeSpan.FromSeconds(0.5),
            };
            animation1.Completed += Animation1_Completed;
            Storyboard.SetTarget(animation1, Splash);
            Storyboard.SetTargetProperty(animation1, new PropertyPath("Opacity"));

            animatin2Visibility = new ObjectAnimationUsingKeyFrames {
                KeyFrames = new ObjectKeyFrameCollection
                {
                    new DiscreteObjectKeyFrame
                    {
                        KeyTime = TimeSpan.FromSeconds(3.5),
                        Value = Visibility.Visible,
                       
                    }
                    ,
                    new DiscreteObjectKeyFrame
                    {
                        KeyTime = TimeSpan.FromSeconds(4.5),
                        Value = Visibility.Hidden
                    }
                },

            
        };
            animatin2Visibility.Completed += Animatin2Visibility_Completed;

            Storyboard.SetTarget(animatin2Visibility, Polar);
            Storyboard.SetTargetProperty(animatin2Visibility, new PropertyPath("Visibility"));

            myStoryboard = new Storyboard();

            myStoryboard.Children.Add(animation1);
            myStoryboard.Children.Add(animatin2Visibility);
            myStoryboard.Duration = new Duration(TimeSpan.FromSeconds(5.0));



        }

I am using the animaition1.completed to turn the visiblity of it to hidden but this doesnt trigger at the correct time

private void Animation1_Completed(object sender, EventArgs e)
        {
            Splash.Visibility = Visibility.Hidden;
        }

The xaml itself is barebones just is a simple user control with currently two images

Cameron
  • 29
  • 4
  • From my research, i discovered that the animation is indeed running for the duration of 2 seconds but the completed event which i use to hide the object doesnt get hit until the end of the storyboard. I found this post which i believe verifies this [HERE](https://stackoverflow.com/questions/39568602/doubleanimation-completed-event-triggered-at-the-end-of-the-storyboard) – Cameron Sep 23 '22 at 09:00

0 Answers0