title: Setting window background color with XAML
body: <p>I have a standard XAML styled window in WPF (&lt; Window ....)</p>
  
  <p>In this window I insert a resource dictionary</p>
  
  <pre><code> &lt;Window.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="Style/Global.xaml" /&gt;
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/Window.Resources&gt;
  </code></pre>
  
  <p>In the Global.xaml dicionary I have the following code:</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;Style TargetType="Window"&gt;
        &lt;Setter Property="Background" Value="Red"/&gt;            
     &lt;/Style&gt;
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>Nothing out of ordinary anywhere.  Except it doesn't work, when I compile and run the app, the window background is shown in default white. BUT in the designer tab in  Visual Studio where you can see the preview of your window, the background color is correctly changed to red. I don't understand.
  I don't have any other styles inserted anywhere that could be overwriting the window's background color.
  So how is it possible that in the preview tab it works correctly, but when i actually run the app, it doesn't? What am I doing wrong here?</p>
  
  <hr>
  
  <p>Here is the entire window code:</p>
  
  <pre><code>&lt;Window x:Class="Apptest.EditBook"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="EditBook" Height="300" Width="300"&gt;
   &lt;Window.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
              &lt;ResourceDictionary Source="Style/Global.xaml" /&gt;
              &lt;ResourceDictionary Source="Style/Controls.xaml" /&gt;
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;
    &lt;/Window.Resources&gt;
          &lt;Grid&gt;
  
     &lt;/Grid&gt;
   &lt;/Window&gt;
  </code></pre>