Reputation: 4567
I'm localizing the app I've built, and I have a problem here.
I added all the strings I use in my xaml in the AppResources.resx file, and I have replaced all the hard-coded strings in the xaml with a binding to the right strings in the .resx file, like this:
Text="{Binding Path=LocalizedResources.StringName, Source={StaticResource LocalizedStrings}}"
The problem is that I need to localize a couple of App Bar buttons and a few Messabe Box, so I need a way to get those strings via C#.
I read a couple of tutorials and I came up with this, as for the localized App Bar button:
ApplicationBar = new ApplicationBar();
ResourceManager rm = new ResourceManager("AppResources", typeof(CreditiInfo).Assembly);
ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/back.png", UriKind.Relative));
appBarButton.Text = rm.GetString("BackAppBar");
ApplicationBar.Buttons.Add(appBarButton);
I get a System.Resources.MissingManifestResourceException when I try to assign to the AppBar button Text the String I retrieve from the GetString method. What am I missing?
Also, I read that when you check a new language in the WMAppManifest.xml file, Visual Studio should automatically copy the actual AppResources.resx file and rename the copy with the new current culture selected, but when I try to add a new language it doesn't work. Do I have to copy and rename the file on my own? Will it recognize the new file when running on a phone that is set on that language?
Thank you for your help!
Sergio
Upvotes: 0
Views: 513
Reputation: 2060
Simply use the auto generated AppResources
class
string resourceValue = AppResources.NameOfYourLocalizedResource;
Upvotes: 1