title: Lazy Instantiation of UserControl
body: <p>I have a WPF application that I am trying to switch the contents of a window efficiently. I have come up with the solution of the following:</p>
  
  <p><b>App.cs</b></p>
  
  <pre><code>internal static Lazy&lt;HomeUserControl&gt; HomePage;
  </code></pre>
  
  <p><b>MainWindow.cs</b></p>
  
  <pre><code>public MainWindow()
     {
         InitializeComponent();
  
         Application.Current.MainWindow.Content = App.HomePage;
  
     }
  </code></pre>
  
  <p><b>HomeUserControl.cs</b></p>
  
  <pre><code>public HomeUserControl()
     {
         InitializeComponent();
     }
  </code></pre>
  
  <p>I am running into a problem that <code>MainWindow.Content</code> is basically being set to a blank window (it is actually changing the content of <code>MainWindow</code>). If I use <code>App.MainWindow.Content = new HomePageUserControl()</code>, everything works as it should. However, I would like to keep one instance of the page, which is why I made a static one in the App class. This problem occurs whether <code>Lazy&lt;&gt;</code> is used or not. I have tried a check to see if <code>HomePage</code> was <code>null</code>, and I got back a label that said <code>Value is not created.</code>, which I'm pretty sure is the representation of an uninitialized <code>Lazy&lt;&gt;</code>; however, this only occurs if I check <code>App.HomePage == null</code>. Any ideas?</p>