title: Animation during SelectionChanged
body: <p>I have a <code>TabControl</code> where each <code>TabItem</code> has a separate control as its <code>Content</code> element. Now, I can easily execute a storyboard when switching to a tab by using a <code>UserControl.Loaded</code> EventTrigger. However, I also want to run an exit animation when switching from one tab to another (i.e. allow the old Content control to animate away, followed by the new Content control's entrance animation).</p>
  
  <p>Is it possible to do this with standard WPF constructs?</p>
  
  <p>If not, how would I go about developing a custom solution that handles this?</p>
  
  <p><strong>Edit:</strong>
  I went ahead and made a modified TabControl that extends the base TabControl and overrode its <code>OnSelectionChanged</code> method as follows:</p>
  
  <pre><code>protected override void OnSelectionChanged(SelectionChangedEventArgs e)
  {
      if (e.AddedItems.Count == 1 &amp;&amp; e.RemovedItems.Count == 1)
      {
          var oldTab = e.RemovedItems[0] as TabItem;
  
          if (oldTab != null)
          {
              var exitStoryboard = /** code to find the storyboard **/
              if (exitStoryboard != null)
              {
                  exitStoryboard.Completed = (_, __) =&gt; base.OnSelectionChanged(e);
                  exitStoryboard.Begin();
                  return;
              }
          }
      }
      base.OnSelectionChanged(e);
  }
  </code></pre>
  
  <p>This works, except when I click between the tabs too quickly in which case the base.OnSelectionChanged never gets called, presumably because the storyboard is not active any more. Tips?</p>