title: Closing all Windows in a C# WPF application
body: <p>I'm creating a little WPF app in <code>VS2013Express</code> and I've come across a little problem.
  You see, there are three windows, <code>MainWindow</code>, <code>LatAndLongDialog</code>, <code>TimeCitiesDialog</code>.</p>
  <p></p>
  `LatAndLongDialog` and `TimeCitiesDialog` are opened from MainWindow (with the click of a button). 
  I want all the other windows to close when the `Closed()` event is called on `MainWindow`. 
  The code on MainWindow.xaml.cs:
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  
  namespace GlobalTime_ELITE_for_WPF
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              InitializeComponent();
              UserDescText.Content =
              &quot;Select a TimeCity or enter the latitude and longitude in \n&quot; +
              &quot;to view the World Time there. Or, select another one of the\n&quot; +
              &quot;options below to do that. Go to Help by clicking on the link\n&quot; +
              &quot;on the upper-right corner of the window to view everything you\n&quot; +
              &quot;can do.&quot;;
              this.Closed += CloseOff;
          }
          private void OpenTimeCitiesDialog(Object Sender, EventArgs E)
          {
              TimeCitiesDialog ObjectReference = new TimeCitiesDialog();
              ObjectReference.Show();
          }
          private void OpenLatAndLongDialog(Object Sender, EventArgs E)
          {
              LatAndLongDialog ObjectReference = new LatAndLongDialog();
              ObjectReference.Show();
          }
          private void CloseOff(Object Sender, EventArgs E)
          {
              this.Close();
              TimeCitiesDialog tcdor = new TimeCitiesDialog();
              LatAndLongDialog laldor = new LatAndLongDialog();
          }
      }
  }
  </code></pre>
  <p>How can I close them all? Please help!</p>