M.S
M.S

Reputation: 1610

Global resources in a class library

In a Silverlight application we can define resources in the App.xaml and have access to them from any XAML document, without having to explicitly merge those resources.

Is there an equivalent solution for a class library? I created a separate resource dictionary in the class library, but I have to merge it as follows before I can use it.

<UserControl.Resources>
 <ResourceDictionary>
  <ResourceDictionary.MergedDictionaries>
   <ResourceDictionary Source="MyResources.xaml" />
  </ResourceDictionary.MergedDictionaries>
 </ResourceDictionary>
</UserControl.Resources>

Is there a way to avoid this? It's rather tedious to do this in every XAML documents for globally used resources.

Upvotes: 6

Views: 1017

Answers (1)

Ken Smith
Ken Smith

Reputation: 20445

I was about to ask this same question. Unfortunately, what you've described is pretty close to what I've been able to come up with. In theory, it seems like you should be able to put these into the library's themes\generic.xaml file, but I haven't been able to make that work -- possibly I'm just doing something boneheaded. The best I've been able to do is just a slightly shorter variant of what you're doing, namely, to leave out the MergedDictionaries syntax:

<UserControl.Resources>
    <commonui:CommonStringsPublic x:Key="commonStrings" />
    <ResourceDictionary Source="/Alanta.Client.UI.Common;component/CommonResources.xaml" x:Key="commonResources" />
</UserControl.Resources>

I'd love to have someone point me to a better solution :-).

Upvotes: 1

Related Questions