title: How to get a static reference to a WPF Window?
body: <p>I've tried a huge amount of ways to get a static reference of my window across my program. I need to access all of its members at runtime from different classes, so a static reference is needed.</p>
  
  <p>What I'd like to have is something like <code>Program.Window1</code>, where <code>Core</code> is static and <code>MyWindow</code> is one of its static members.</p>
  
  <p>In WinForms, I usually declare my static form in Program.cs, but this does not seem to work with WPF and their custom "App.xaml" ApplicationDefinition. </p>
  
  <p>How can I do it?</p>
  
  <p>Note: I have tried a number of ways already: using a direct call to a new window (i.e. <code>Program.Window1 = new Window1()</code>) will not work, as I get some thread invalidity exception. As I understand so far, only ApplicationDefinitions can launch windows in WPF.</p>
  
  <p>Here is the exception whenever I try to create a window "by code" and not by the default XAML ApplicationDefinition's StartupUri:</p>
  
  <blockquote>
    <p>The calling thread must be STA, because many UI components require this.</p>
  </blockquote>