Search code examples
silverlight-4.0resxxap

Access resx in application from Silverlight class library


Resource files in Silverlight can be accessed using the code below:

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

However in my application this piece of code is not in the application itself, but in a Silverlight class library and the app has reference to it; changing the namespace to the "MyAppNamespace" just generates error.

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


Solution

  • In order to achieve what I wanted I had to do the following:

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

    And after that I can create ResourceManager with the resources like this:

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

    where name is the path from my first post.