Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 359
M.S Avatar asked Jan 24 '11 23:01

M.S


People also ask

What is global resource give example?

Global Resources. Global resources can be as easy as basic needs. Like food, clothing, shelter, leisure and cultural activities.

What is the extension of a resource file in ASP net?

Resource files in ASP.NET have a . resx extension. Each localized resource file contains name/value pairs. You can use a text editor to customize a resource file's string values.


1 Answers

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 :-).

like image 72
Ken Smith Avatar answered Oct 14 '22 05:10

Ken Smith