title: How to close a hidden window (WPF application)?
body: <p>In my application (WPF) i have this window:</p>
  
  <p><code>public partial class Window1 : Window</code> and in the Xaml <code>x:Class="WpfApplication1.Window1"</code></p>
  
  <p>Now, when i switch to and from the main to window 1 and back, i us the Visibility.Hidden and Visibility.Visible to hide them and make them show again to the user.</p>
  
  <p>What i try to do now, is make a test button in the main window, that says: Close Window1.
  This window is hidden, but i really want to close it in the background.
  at first i though to just use the <code>Window.Close();</code> but that does not seem to do the trick.</p>
  
  <p>So, how should i do this in a correct way ?
  Thank you very much in advance.</p>
  
  <p><em><strong>EDIT 1 - making question more clear</em></strong></p>
  
  <p>To open the window1 in my Main window, i use this part</p>
  
  <pre><code>Window1 W1 = null; // Initialise Field.
    public void CalcTabel_Click(object sender, RoutedEventArgs e)
     {
      if (W1 == null)
      {
       W1 = new Window1();
       W1.Hoofdmenu = this;
       W1.checkLang();
       W1.Show();
      }
     else
      {
       W1.checkLang();
       W1.Visibility = Visibility.Visible;
      }
     this.Visibility = Visibility.Hidden;
     }
  </code></pre>
  
  <p>On window 1 there is a Back button, that has this snip-it of code in it (Where "Hoofdmenu" us the main window):</p>
  
  <pre><code>Hoofdmenu.updateStatistics();
  Hoofdmenu.Visibility = Visibility.Visible;
  this.Visibility = Visibility.Hidden;
  </code></pre>
  
  <p>But again, this time <strong>when standing in the main window (so window 1 is hidden)</strong> i want to close down that window 1. but using <code>W1.Close()</code> does not seem to work. So i am looking for a way to Close that window 1, <strong>not</strong> change its visibility.</p>
  
  <p><em><strong>EDIT 2 - Solution</em></strong></p>
  
  <p>So using <code>W1.Close();</code> did <strong>not</strong> work, although a small change <code>this.W1.Close();</code> did work in fact :)</p>