Access resx in an application from the Silverlight class library

Resource files in Silverlight can be obtained using the following code:

ResourceManager rm = new ResourceManager("MyLibraryNamespace.MyFolder.MyResources", Assembly.GetExecutingAssembly());

However, in my application this piece of code is missing in the application itself, but there is a link to it in the Silverlight class library and in the application; changing the namespace in "MyAppNamespace" just raises an error.

How can I get resources in xap file from Silverlight class library?

0
source share
3 answers

To achieve what I wanted, I needed to do the following:

var assembly = Application.Current.GetType().Assembly;

And after that, I can create a ResourceManager with resources such as this:

var rm = new System.Resources.ResourceManager(name, assembly);

where name is the path from my first message.

0
source

: http://msdn.microsoft.com/en-us/hh336287

, "", XAML. MSDN:

public class LocalizedStrings {
  public LocalizedStrings() { }
  private static sdkGlobalizationCS.AppResources localizedResources = new sdkGlobalizationCS.AppResources();
  public sdkGlobalizationCS.AppResources LocalizedResources { get { return localizedResources; } }
}

XAML ( ):

<ListBoxItem Content="{Binding Path=LocalizedResources.LangRegionNameFrFR, Source={StaticResource LocalizedStrings}}" />
+1

This is good, and I was able to do the same.

In my case, I have the same library shared between applications, so I dynamically retrieve the assembly name:

var ast = assembly.FullName;
char[] delimit = new char[] { ',' };
string[] parts = ast.Split(delimit);
var gResources = new System.Resources.ResourceManager(parts[0]+"resource path here", assembly);
+1
source

All Articles