title: How can I make sure only one WPF Window is open at a time?
body: <p>I have a WPF window that I am launching from inside of a winform app. I only want to allow once instance of that WPF window to be open at a time, and not warn that user if they try to open it again.</p>
  
  <p>I am having a problem however trying to search for that WPF window being open because the window is being launched from a winform. What I normaly do is when searching for a winform, I search for any instances of that winform existing in the <code>Application.Current.OpenForms</code>, and when in WPF I search for <code>Application.Current.Windows</code></p>
  
  <p>The problem I have is that <code>System.Windows.Application.Current</code> is null when launched from inside of a winform, so I can't search for the WPF window that way. Is there any better way of searching for an existing instance of an open window?</p>
  
  <p>My Code:</p>
  
  <pre><code>if (System.Windows.Application.Current != null)
                  {
                      foreach (System.Windows.Window win in System.Windows.Application.Current.Windows)
                      {
                          if (win is frmCaseWpf)
                          {
                              MessageBox.Show("You may have only one active case open at a time.", "Open Case",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Stop);
  
                              win.WindowState = System.Windows.WindowState.Normal;
                              win.Focus();
                              win.Activate();
                              return;
                          }
                      }
                  }
  </code></pre>