title: Get a Resource from a ResourceDictionary with a key
body: <p>I have a WPF window that is supposed to load two vector images from XAML files. (Each one is in a separate file for easier modification in Expression Design.)</p>
  
  <p>When I include the XAML files in a <code>MergedDictionary</code>, it works fine.
  Here is the code I use:</p>
  
  <pre><code>&lt;Window.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="Images/LCCD logo.xaml" /&gt;
              &lt;ResourceDictionary Source="Images/LCCD bottom image.xaml" /&gt;
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;Image Source="{Binding Source={StaticResource LCCDlogo}}" /&gt; &lt;!-- Simplified --&gt;
  &lt;Image Source="{Binding Source={StaticResource LCCDbar}}" /&gt; &lt;!-- Simplified --&gt;
  </code></pre>
  
  <p>However, I now need to add more to the Window's resources.  The new resource belongs to this Window so we want it to be in the same file instead of an included file.</p>
  
  <p>When I add the following code between <code>&lt;Window.Resources&gt;</code> and <code>&lt;ResourceDictionary&gt;</code>, I get the following error:</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>&lt;Style TargetType="{x:Type tab:FabTabItem}"&gt;
          &lt;Setter Property="Header" Value="{Binding Path=LabelText}"/&gt;
          &lt;Setter Property="HeaderTemplate"&gt;
              &lt;Setter.Value&gt;
                  &lt;DataTemplate&gt;
                      &lt;StackPanel Orientation="Horizontal" Margin="0,0,4,0"&gt;
                          &lt;TextBlock Text="{Binding}" TextTrimming="CharacterEllipsis"/&gt;
                      &lt;/StackPanel&gt;
                  &lt;/DataTemplate&gt;
              &lt;/Setter.Value&gt;
          &lt;/Setter&gt;
      &lt;/Style&gt;
  </code></pre>
  
  <p><strong>Warning</strong></p>
  
  <blockquote>
    <p>The designer does not support loading dictionaries that mix
    'ResourceDictionary' items without a key and other items in the same
    collection. Please ensure that the 'Resources' property does not
    contain 'ResourceDictionary' items without a key, or that the
    'ResourceDictionary' item is the only element in the collection.</p>
  </blockquote>
  
  <p>So I change the <code>&lt;ResourceDictionary&gt;</code> tag to this:</p>
  
  <pre><code>&lt;ResourceDictionary x:Key="Images"&gt;
  </code></pre>
  
  <p>However, I don't know how to access the resources inside this Dictionary now.  How do you get the resources from inside a named <code>ResourceDictionary</code>?</p>
  
  <hr>
  
  <p><strong>EDIT</strong></p>
  
  <p>Never mind.  This compiles but doesn't run.</p>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>''Resources' property has already been set on 'MainWindow'.</p>
  </blockquote>
  
  <p>I guess I'll have to do it some other way.</p>