title: Using WPF background from resource dictionary
body: <p>My WPF application has several windows and I want to use the same background image for all of them.  I've defined the bitmap and image brush in a resource dictionary as follows.</p>
  
  <pre><code>&lt;BitmapImage x:Key="BackgroundImage" UriSource="/Resources/BackPlate.png"/&gt;
  &lt;ImageBrush x:Key="BackgroundBrush" ImageSource="{StaticResource BackgroundImage}" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,128,128"/&gt;
  </code></pre>
  
  <p>When I set the background property in the Window description, the background changes successfully in Visual Studio, but when I run the application, I get a parsing exception, I assume because the window resources haven't actually been read yet?</p>
  
  <pre><code>&lt;Window x:Class="MyApp.Test"
  ...
      Background="{StaticResource BackgroundBrush}"&gt;
  &lt;Window.Resources&gt;
  ...
  </code></pre>
  
  <p>Is there another way to specify the background after the resources have been read?  I've tried the Window.Background approach, but I can't figure out how to get it to work w/o specifying the whole image brush definition.</p>
  
  <pre><code> &lt;Window.Background&gt;
      &lt;ImageBrush ?&gt;
  &lt;/Window.Background&gt;
  </code></pre>
  
  <p>Is there a way to specify the image brush by reference when using this approach?</p>