Run something after an animation - WPF

Asked

Viewed 81 times

0

I have the following animation when I start my project:

    public ConfigInicial_Empresa()
    {
        InitializeComponent();

        brush = (Brush)bc.ConvertFrom("#444");
        window.Background = brush;

        DoubleAnimation fadingAnimation = new DoubleAnimation();
        fadingAnimation.BeginTime = TimeSpan.FromMilliseconds(500);
        fadingAnimation.From = 0;
        fadingAnimation.To = 2;
        fadingAnimation.Duration = TimeSpan.FromSeconds(1.75);
        fadingAnimation.AutoReverse = true;

        tbBemVindo.BeginAnimation(TextBlock.OpacityProperty, fadingAnimation);
    }

I would like to perform something right after this animation is over...

How can I succeed at this task?

Thank you in advance...

1 answer

1


Simply place a Handler signature on Completed before calling beginAnimation.

 public ConfigInicial_Empresa()
    {
        InitializeComponent();

        brush = (Brush)bc.ConvertFrom("#444");
        window.Background = brush;

        DoubleAnimation fadingAnimation = new DoubleAnimation();
        fadingAnimation.BeginTime = TimeSpan.FromMilliseconds(500);
        fadingAnimation.From = 0;
        fadingAnimation.To = 2;
        fadingAnimation.Duration = TimeSpan.FromSeconds(1.75);
        fadingAnimation.AutoReverse = true;
        fadingAnimation.Completed += new EventHandler(fadingAnimation_Completed);
        tbBemVindo.BeginAnimation(TextBlock.OpacityProperty, fadingAnimation);
    }

private void fadingAnimation_Completed(object sender, EventArgs e)
{
    //NXZERO > METALLICA
}

Source -> https://msdn.microsoft.com/pt-br/library/system.windows.media.animation.timeline.completed(v=vs.110). aspx

  • I had tried it this way, put the fadingAnimation.Completed under tbBemVindo.Beginanimation and it didn’t work... Because it will be?

  • 1

    Simple, you gave START in animation. It’s over. and only then did you speak for after it’s over (SHE ALREADY IS OVER) do you want an action to happen... then it doesn’t work... this rule goes for other things in programming.

  • It makes sense... Thank you :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.