title: WPF global styles problem with .Net4
body: <p>I have just changed my WPF application from .Net3.5 to .Net4. Doing this caused all my global styles to stop working. Only the styles explicitly set using a key did work. I've done some research and figured out what causes this, and reproduced it in a simple app. </p>
  
  <p>I have a simple WPF app containing only a button with text - no style or anything else. I define a style for all buttons in the ResourceDictionary of App.Xaml: </p>
  
  <pre><code>&lt;Style TargetType="{x:Type Button}"&gt;
      &lt;Setter Property="Background" Value="Red"&gt;&lt;/Setter&gt;
  &lt;/Style&gt;
  </code></pre>
  
  <p>My button is now Red - all fine. I now move this to a separate ResourceDictionary in a separate project. This is where I want to hold all my shared styles. The button is still red, and my reference from App.xaml to SharedStyles.xaml looks like this: </p>
  
  <pre><code>&lt;Application.Resources&gt;
      &lt;ResourceDictionary&gt;
          &lt;ResourceDictionary.MergedDictionaries&gt;              
             &lt;ResourceDictionary Source="/StyleLib;component/SharedStyles.xaml"/&gt; 
          &lt;/ResourceDictionary.MergedDictionaries&gt;
      &lt;/ResourceDictionary&gt;
  &lt;/Application.Resources&gt;
  </code></pre>
  
  <p>Now - I want SharedStyles.xaml of StyleLib to hold all specific style definitions, so I create a new file in the same project called ButtonStyles.xaml, and I add the resource there. Actually - I add another style too with a key to be used explicitly (technically I added this later, so this does not have anything to do with the problem that occurs). </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="{x:Type Button}"&gt;
          &lt;Setter Property="Background" Value="Red"&gt;&lt;/Setter&gt;
      &lt;/Style&gt;
  
      &lt;Style x:Key="Explicit" TargetType="{x:Type Button}"&gt;
          &lt;Setter Property="Background" Value="Blue"&gt;&lt;/Setter&gt;
      &lt;/Style&gt;    
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>ButtonStyles.xaml is referenced from SharedStyles.xaml: </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;ResourceDictionary Source="/StyleLib;component/ButtonStyles.xaml"/&gt;
      &lt;/ResourceDictionary.MergedDictionaries&gt;   
  &lt;/ResourceDictionary&gt;
  </code></pre>
  
  <p>Now - my button control is not styled any more. Actually - it is still shown as styled in the preview-window in VS2010, but when I run the application they aren't styled. If I explicitly reference the style with key "Explicit" they get this style - so the file is successfully included. </p>
  
  <p>Another funny thing is that if I now add another style in SharedStyle.xaml - e.g. a global style for StackPanel (which was what I tried) - then the global style inside ButtonStyle.xaml magically starts working..! </p>
  
  <p>My question now is if I'm doing something wrong, or if this sounds like a bug in .Net4? Sounds like a bug to me.. This did work just fine in .Net3.5! </p>