简体   繁体   中英

StaticResource where resource is in external assembly?

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM