title: WPF Project with null reference exception
body: <p>I have a WPF project were I am using multiple WPF windows.
  My WPF Windows are:</p>
  
  <ul>
  <li>MainWindow</li>
  <li>Window1</li>
  <li>Login</li>
  </ul>
  
  <p>I have to case scenarios, in the first one everything works fine but in the second I get a null reference exception.</p>
  
  <ol>
  <li>First Scenario:
  App.xaml is configured so as startup window to be <code>MainWindow</code>.</li>
  </ol>
  
  <p>When user clicks on Button on MainWindow he is forwarded in Window1 were I have the following code:</p>
  
  <pre><code>MainWindow obj=(MainWindow)Application.Current.MainWindow;
   private void button1_Click(object sender, RoutedEventArgs e)
          {
          obj.checkBox1.IsChecked = false;
          }
  </code></pre>
  
  <p>2.Second Scenario:
  App.xaml is configured so as startup window to be Login Window.
  Code in Login:</p>
  
  <pre><code>private void button1_Click(object sender, RoutedEventArgs e)
          {
          var window=new MainWindow();
          window.Show();
          this.Close();
          }
  </code></pre>
  
  <p>In this scenario when I click on button in Window1 a null reference exception is thrown for obj.</p>
  
  <p>What is the difference in the initialization of <code>MainWindow</code> in these 2 cases that causes the exception in the 2nd case and how can I overcome it?</p>