title: Hosting a composite WPF application inside an Element Host
body: <p>I'm hosting a WPF application inside an Element Host, and it has a WPF user control inside the application. At a certain moment inside the WPF application (since I know that the <code>Application</code> class will be <code>null</code>, I instantiate it like so :</p>
  
  <pre><code>    if (Application.Current == null)
      {
          // create the Application object
          new Application();
  
          // merge in your application resources
          Application.Current.Resources.MergedDictionaries.Add(
              Application.LoadComponent(
                  new Uri("edit;component/Styles/Styles.xaml",
                  UriKind.RelativeOrAbsolute)) as ResourceDictionary);
      }
  </code></pre>
  
  <p>The problem is that whenever I close the inner user control inside the WPF application, it causes for some reason the Resources to be inaccessible. It says that the <code>Application</code> object is <code>null</code> even through I did instantiate it at the start of the application. If I check  the <code>Application</code> for <code>null</code> and then instantiate it it says that there is an active Application in the current AppDomain. </p>