title: WPF Storyboard beginner problem
body: <p>I'm writing my first WPF application and I'm trying to implement a fade animation when the form closes. I came across this question <a href="https://stackoverflow.com/questions/867656/fading-out-a-wpf-window-on-close">Fading out a wpf window on close</a> which shows how to make a fade-out animation but I can't seem to get it working. I have this in my XAML:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;Storyboard Name="FadeOutStoryboard" x:Key="FadeOutStoryboard" Completed="FadeOutStoryboard_Completed"&gt;
          &lt;DoubleAnimation Storyboard.TargetProperty="Window.Opacity" From="1" To="0" Duration="0:0:2" FillBehavior="HoldEnd" /&gt;
      &lt;/Storyboard&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>And I then have this event handler:</p>
  
  <pre><code>    private bool doneFade;
      private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
      {
          if (!doneFade)
          {
              e.Cancel = true;
              Storyboard sb = (Storyboard)this.FindResource("FadeOutStoryboard");
              sb.Begin();
          }
      }
  </code></pre>
  
  <p>But when the <code>sb.Begin()</code> method is called I get this exception:</p>
  
  <pre><code>System.InvalidOperationException: No target was specified for 'System.Windows.Media.Animation.DoubleAnimation'.
  </code></pre>
  
  <p>As stated this is my first attempt at WPF so I'm rather comfused at what I need to do to add the fade-out when the form is closing.</p>