title: Event after double animation whilst keeping context
body: <p>I am trying to create an animation but am having problems executing some code after the animation has occured. The animation code is as follows...</p>
  
  <pre><code>public static void Friend(Canvas canvas)
  {
      foreach (var element in canvas.Children.OfType&lt;Image&gt;())
      {
          var elementName = Regex.Split(element.Name, "_");
          if (elementName[0] == "friend")
          {
              var slideDown = new DoubleAnimation
                  {
                      From = Canvas.GetBottom(element),
                      To = Canvas.GetBottom(element) - element.Height,
                      Duration = new Duration(TimeSpan.FromSeconds(1)),
                      AutoReverse = true
                  };
              element.BeginAnimation(Canvas.BottomProperty, slideDown);
              slideDown.Completed += (sender, e) =&gt; Test(sender, e, element, canvas);
          }
      }
  }
  </code></pre>
  
  <p>The event to happen afterwards is...</p>
  
  <pre><code>var random = new Random();
  element.Source = Core.StreamImage(Wardrobe.Friends[Wardrobe.RandomFriend()]);
  Canvas.SetLeft(element, random.Next(0, (int)(canvas.ActualWidth - element.Width)));
  // then reverse the previous animation.
  </code></pre>
  
  <p>As you can see, the event needs to keep the context of the animation in order for it to work but event handlers don't allow this. I have tried adding this code directly underneath the <code>element.BeginAnimation</code> but it is executed prematurely. </p>
  
  <p>I have also tried splitting the parts of the animation up into seperate functions but of course you can't have multiple animations on one object as the functions don't get executed in order resulting in only the last section being played.</p>