title: Close WPF window after animation
body: <p>I'm using an animation to cause a window to fade out of focus, then close.</p>
  
  <p>However, the close event occurs immediately after the animation.</p>
  
  <p>What is the simplest way to make the window close after the animation?</p>
  
  <p>In the following code, MainWindow is the second window that is being opened. This method is called when a button is clicked in the first window.</p>
  
  <pre><code>private void CloseMethod(object sender, RoutedEventArgs e)
  {
      MainWindow win = new MainWindow();
      win.Show();
      DoubleAnimation animation = new DoubleAnimation()
      {
          From = 1.0,
          To = 0.0,
          Duration = new Duration(TimeSpan.FromSeconds(2))
      };
      this.BeginAnimation(Window.OpacityProperty, animation);
      this.Close();
  }
  </code></pre>