Question

I'm trying to use resource files (.resx) in a class library. I'm having trouble using these resources in my library's XAML files because libraries do not come with an App.xaml file. So I can not do:

<Application.Resources>
     <local:LocalizedStrings xmlns:local="clr-namespace:WPLocalization" x:Key="LocalizedStrings" />
</Application.Resources>

How do I go about localizing a self-contained WP8 library/assembly?

Was it helpful?

Solution

I found a way but it's rather a work around.

The solution is not to try to localize your controls from XAML, but instead from your behind code.

For example, you define a Button in XAML as follows:

<Button Name="MyButton" />

And then in your partial class behind you set the content of the button programatically as follows:

MyButton.Content = MyLocalizedStrings.Hello;

Of course, in this example you would have a resource file called "MyLocalizedStrings.resx" in your project with a string named "Hello" in it.

This approach solves the problem. The only down side is that you won't be able to see a preview of the localized XAML in the Visual Studio XAML window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top