title: How to check WPF window open or close
body: <p>I want to check if some window is opened or closed. If the window is already open <strong><em>focus it</em></strong>. if the window is already close, open the window.</p>
  
  <p>I use this code:</p>
  
  <pre><code>public static bool IsWindowOpen&lt;T&gt;(string name = "") where T : Window
  {
     return string.IsNullOrEmpty(name)? Application.Current.Windows.OfType&lt;T&gt;().Any(): Application.Current.Windows.OfType&lt;T&gt;().Any(w =&gt; w.Name.Equals(name));
  }
  
  private void MenuItem1_OnClick(object sender, RoutedEventArgs e)
  {
      if (IsWindowOpen&lt;Window&gt;("TestForm")) return;
      var window1 = new Window1 { Name = "TestForm", Title = "Welcome", };
      window1.Show();
  }
  </code></pre>
  
  <p>Can you help with this?</p>