Question

Basically, I want to keep all my XAML resources in an external assembly (for my styles). I have a reference of this external assembly in my application.

Is there something to do with satellite assemblies or whatnot or how do I go about accessing these styles so that my application can still have StaticResource tags without compilation errors?

Was it helpful?

Solution

Assuming you keep your styles in a ResourceDictionary in the other assembly, you just need to merge it with your current resources (whether they are on a Window or UserControl or whatever).

If we assume that

  • your other assembly is named 'external.assembly.name'
  • the ResourceDictionary is under the namespace Resources; and
  • the dictionary is named 'MyStyles.xaml'

...then you can merge the dictionaries as below:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary 
              Source="pack://application:,,,/external.assembly.name;component/Resources/MyStyles.xaml" />
        </ResourceDictionary.MergedDictionaries>
        <!-- other resources go here -->
    </ResourceDictionary>
</UserControl.Resources>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top