WPF Animation Completed Event


  • Hi All,

    I am trying to animate an object vertically, from point A to B , i am using a ThicknessAnimation to achieve this. However i noticed that if i place the duration of the animation to 100 ms, the Completed event is being called before the animation is actually completed. I noticed this by placing a message box in the Completed event handler. Visually i notice that the animation stopped a little before the end when the messagebox appeared. Could i be doing something wrong?

    23/ربيع الأول/1430 07:32 ص

جميع الردود

  • Hi,

    Could you please provide a simplified example to demonstrate the issue you are encountering?


    Jim Zhou -MSFT
    25/ربيع الأول/1430 01:53 م
  • I have used similar thing in my article

    please go through it, I have explained I hope this will help you :)

    Prasad -
    • تم الاقتراح كإجابة بواسطة prasad22 25/ربيع الأول/1430 04:41 م
    25/ربيع الأول/1430 04:41 م
  • Hi All,

    Below is a small portion of my code.

    <Storyboard x:Key="HighLightAnim">
                <ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="highlight_bar" Storyboard.TargetProperty="(FrameworkElement.Margin)">

    C# Code behind:

     void OnAnimationCompleted(object sender, EventArgs e)


    private void Animate()
     Storyboard stb_hightLightAnim = (Storyboard)this.Resources["HighLightAnim"];
     stb_hightLightAnim.Completed += new EventHandler(OnAnimationCompleted);
    ThicknessAnimationUsingKeyFrames highlightThicknessAnim;
                    highlightThicknessAnim = (ThicknessAnimationUsingKeyFrames)stb_hightLightAnim.Children[0];
                    highlightThicknessAnim.KeyFrames[0].Value = new Thickness(0, 0, 0, 0);
                    highlightThicknessAnim.KeyFrames[1].Value = new Thickness(0, 47, 0, 0);
                    highlightThicknessAnim.KeyFrames[0].KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100));
                    highlightThicknessAnim.KeyFrames[1].KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(100));


    The message box is appearing before the animation is complete .

    25/ربيع الأول/1430 05:26 م
  • private void Animate()
        Storyboard stb_hightLightAnim = (Storyboard)this.Resources["HighLightAnim"];
        stb_hightLightAnim.Completed += ((s,e)=>MessageBox.Show("Completed"));
        // your other codes.
    stb_hightLightAnim.Begin(this); }
    try that.
    04/جمادى الثانية/1430 01:34 م
  • I used the StoryBoard component, which has a Completed event.
    05/رجب/1431 01:48 ص
  • I ran into this bug as well.

    Please, answer paolo if you found solution

    08/محرم/1432 12:11 م