title: Wpf merged resource dictionary no being recognized from app.xaml
body: <p>I have a WPF .net 4.5 application where I am having trouble merging resource dictionaries.</p>
  
  <p>I have the exact same problem as <a href="https://stackoverflow.com/a/4166345/1923268">This SO question</a> and <a href="https://stackoverflow.com/a/4113594/1923268">This Question</a> but the accepted solution does not work for me.  </p>
  
  <p>I have a resource dictionaries declared in my app.xaml as follows (simplified for clarity):</p>
  
  <pre><code>&lt;Application.Resources&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="Skin/ResourceLibrary.xaml" /&gt;              
              &lt;ResourceDictionary Source="Skin/Brushes/ColorStyles.xaml" /&gt;               
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;               
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p><strong>Problem:</strong>
  The app can "SEE" the ColorStyles dictonary when listed in app.xaml, but if I move/nest it inside the ResourceLibrary.xaml, then the ColorStyles.xaml are not "seen" by the app and errors about missing static resources appear.</p>
  
  <p>Here is how I create the ResourceLibrary.xaml dictionary (simplified):</p>
  
  <pre><code>&lt;ResourceDictionary 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
  
      &lt;ResourceDictionary.MergedDictionaries&gt;
  
          &lt;!--  BRUSHES AND COLORS  --&gt;
          &lt;ResourceDictionary Source="Brushes/ColorStyles.xaml" /&gt;
  
      &lt;/ResourceDictionary.MergedDictionaries&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p><strong>Reason for change:</strong> My current organization of my resource dictionaries is awful and I need to change it (as I am creating objects more than once).  I wanted to have one resource dictionary in a "Skin" folder and then sub-folders for organizing the remaining style dictionaries which would all be merged in the ResourceLibrary.xaml file which in turn would be called in app.xaml.</p>
  
  <p><strong>What I tried:</strong>
  Yes I did try to use the solution from the link above:</p>
  
  <pre><code>&lt;Application.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="Skin/ResourceLibrary.xaml"/&gt;
          &lt;/ResourceDictionary.MergedDictionaries&gt;
          &lt;!-- Dummy Style, anything you won't use goes --&gt;
          &lt;Style TargetType="{x:Type Rectangle}" /&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>but I get the following error on the dummy style line:</p>
  
  <blockquote>
    <p>Error 2   Property elements cannot be in the middle of an element's
    content. They must be before or after the content.</p>
  </blockquote>
  
  <p>Changing the code to the following got rid of the error above, thanks to lisp comment:</p>
  
  <pre><code>&lt;Application.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;!--Global View Model Locator--&gt;
          &lt;vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" /&gt;
  
          &lt;!-- Dummy Style, anything you won't use goes --&gt;
          &lt;Style TargetType="{x:Type Rectangle}" /&gt;
  
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="Skin/ResourceLibrary.xaml"&gt;&lt;/ResourceDictionary&gt;             
              &lt;ResourceDictionary Source="Skin/Brushes/ColorStyles.xaml" /&gt;
              &lt;ResourceDictionary Source="Skin/NamedStyles/AlertStyles.xaml" /&gt;
  
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;               
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>but the Resource Library is still not being called.</p>
  
  <p>I also tried to change all the file paths to pack URI's, but that did not solve the problem either.</p>
  
  <p>I tried moving the resourceLibrary.xaml and the other resource dictionaries into a different class library project (using the same folder structure and files as above).  I then used the following URI but I still am not able to access resources declared in the ResourceLibrary.xaml file.</p>
  
  <pre><code>&lt;ResourceDictionary Source="pack://application:,,,/FTC.Style;component/ResourceLibrary.xaml" /&gt;
  </code></pre>
  
  <p>But again, if I add each resource dictionary to the App.Xaml file, using the UIR format above, the resources are usable.</p>
  
  <p>The error is gone, but I am still unable to use resources that are a part of the merged dictionary in the ResourceLibrary.xaml file.  I am inclined to agree with the comment of dowhilefor as to whether or not I should use this approach, but I want to figure this out because the most common solution to this problem (see links at top of this post) is not working and maybe this solution could help someone else.  </p>
  
  <p><strong>Question:</strong>  Why is the ResourceLibrary.xaml file being ignored?</p>