title: Inheriting from Application Styles (WPF)
body: <p>I am trying to inherit application-level styles for a certain <code>Window</code> in my WPF application, but I'm having trouble getting it to inherit rather than simply override the existing styles.</p>
  
  <p>In <em>App.xaml</em> (under the <code>App.Resources element</code>) I define a style as such:</p>
  
  <pre><code>&lt;Style TargetType="Button"&gt;
      &lt;Setter Property="Padding" Value="6"/&gt;
      &lt;Setter Property="FontWeight" Value="Bold"/&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>And in the XAML fora a certain <code>Window</code>, I define the following under <code>Window.Resources</code>:</p>
  
  <pre><code>&lt;Style TargetType="Button" BasedOn="{StaticResource {x:Type Button}}"&gt;
      &lt;Setter Property="Padding" Value="6"/&gt;
      &lt;Setter Property="FontWeight" Value="Bold"/&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>The problem here is that the former (app) style is ignored as if the latter (window) style has overridden it. The <code>BasedOn</code> attribute is set, which is intended to indicate that existing styles should be inherited, as far as I know. Removing the attribute doesn't help either. The only potential cause of which I can think is that <code>{StaticResource {x:Type Button}}</code> only refers to the default WPF style and not the one I have define in <em>App.xaml</em>.</p>
  
  <p>I am aware that this styling behaviour would be possible to accomplish using the <code>x:Key</code> attribute, but I was hoping for a more elegant way that allows me to apply styles with inheritance to all controls within a scope (i.e. application/window).</p>
  
  <h2>Update</h2>
  
  <p>Thanks for both of your replies. You are indeed right that things work as expected in a sample application. The difference is that I inadvertently failed to mention that the style in <code>App.xaml</code> is contained within a <code>ResourceDictionary</code>, as such:</p>
  
  <pre><code>&lt;Application.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;
  
              &lt;ResourceDictionary Source="SettingsDictionary.xaml"/&gt;
  
              &lt;ResourceDictionary&gt;
  
                  &lt;Style x:Key="DefaultButton" TargetType="Button"&gt;
                      &lt;Setter Property="Padding" Value="4"/&gt;
                      &lt;Setter Property="HorizontalAlignment" Value="Center"/&gt;
                      &lt;Setter Property="VerticalAlignment" Value="Center"/&gt;
                  &lt;/Style&gt;
  
              &lt;/ResourceDictionary&gt;
  
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>Any suggestion on how to remedy matters in this case?</p>