Using Styles From Different Class Library In Silverlight

For re-use purposes, it is helpful to put Silverlight styles into a separate class library; let’s call it ResourceLibrary in this example.

In the class library which is using the styles from ResourceLibrary, one should declare a Styles.xaml, which only contains a reference to ResourceLibrary:

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary 
      Source="/ResourceLibrary;component/Assets/Styles.xaml"/>
  </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

The using class library is called UsingLibrary here.
To be able to render the controls contained in UsingLibrary in Visual Studio’s designer, the xaml needs to contain the following declaration:

<UserControl.Resources>
  <ResourceDictionary 
    Source="/ResourceLibrary;component/Assets/Styles.xaml"/>
</UserControl.Resources>

For some kind of controls, this code is not valid, e.g. for controls based on Telerik's RadWindow class.
So I took the following approach:

<Control.Resources>
  <ResourceDictionary 
    Source="/ResourceLibrary;component/Assets/Styles.xaml"/>
</Control.Resources>

The designer was happy (styles were resolved in design mode), the compiler was happy too, but the runtime wasn't.

An exception occurred complaining that "Local values are not allowed in resource dictionary with Source set". Whatever that means…

The way out was to replace the resource dictionary declaration with the following code:

<Control.Resources>
  <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
      <ResourceDictionary 
        Source="/ResourceLibrary;component/Assets/Styles.xaml"/>
    </ResourceDictionary.MergedDictionaries>
  </ResourceDictionary>
</Control.Resources>

To me, a little bit unexpected. Why does the designer and the compiler like the short version, while the runtime doesn't?!

The environment was VS 2010 SP1 and Silverlight 4.