WPF: Sharing resources across assemblies

2019-03-06 11:16发布

问题:

I previously posted a question on sharing resources across assemblies using Themes/generic.xaml and the ComponentResourceKey markup extension. The solution works nicely, but it requres all of the shared resources to be located in the generic.xaml resource dictionary. Mine is getting rather large, so I thought I would use merged dictionaries in generic.xaml to organize things.

I have had no luck so far. I ran some tests using the demo from my previous post, and as soon as I move resources to a merged dictionary, the ComponentResourceKey fails, complaining that it can't find the source file for the merged dictionary.

Has anyone else gotten this working? How? Thanks for your help.

回答1:

You could use WPF Resource Dictionary in a separate assembly