title: MergedDictionaries in XAML rewritten to code
body: <p>Is
  this XAML code in <strong>App.xaml</strong>:</p>
  
  <pre><code>&lt;Application x:Class="Company.Product.App"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      &gt;
      &lt;Application.Resources&gt;
        &lt;ResourceDictionary&gt;
            &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/System.Windows.xaml"/&gt;
              &lt;ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.xaml"/&gt;
              &lt;ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.Data.xaml"/&gt;               
            &lt;/ResourceDictionary.MergedDictionaries&gt;
        &lt;/ResourceDictionary&gt;
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>equivalent to:</p>
  
  <p><strong>App.xaml</strong>:</p>
  
  <pre><code>&lt;Application x:Class="Company.Product.App"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      &gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>and in <strong>App.xaml.cs</strong>:</p>
  
  <pre><code>public partial class App : Application
  {
      public App()
      {               
          Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
          {
              Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/System.Windows.xaml", UriKind.RelativeOrAbsolute)
          });
          Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
          {
              Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.xaml", UriKind.RelativeOrAbsolute)
          });
          Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
          {
              Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.Data.xaml", UriKind.RelativeOrAbsolute)
          });
      }
  }
  </code></pre>
  
  <p><br /><br>
  <em>One side note:</em> Do I need to call Application.Current.Resources.MergedDictionaries.Clear();  in this situation before i start adding the merged dictionaries? I think at this moment the default 
  MergedDictionaries collection is initially empty.     </p>