I know all about the old-school way: use a resource file with the .resx extension, provide a NeutralResourcesLanguage attribute, the neutral resource is compiled in the assembly, and you can compile satellite assemblies from other localized resources (blahblah.de-DE.resx). Visual Studio also generates a strongly typed .cs from the resources so it's easy to use from code (Properties.Resources.Default.WhateverStringResource).
I just learned the new WPF way: put the resources inside the .xaml file, use the UICulture tag in the .csproj to put the .baml resource in a satellite assembly, or not, and put the .baml resource in the main assembly. These resources are easy to use inside the .xaml but AFAIK, not from code, since no .cs file is auto-generated.
So maybe I'm very mistaken, but I have several questions. "Seriously, what the hell now?" being the first. To make my ranting valid, just create a new WPF application in Visual Studio 2010: you'll get .xaml files and it will also put an empty Properties\Resources.resx there. There you have it, so they do need to coexist.
First of all, do I need both new and old-school anyway? I can't see an easy way to use strongly typed .xaml resources from the code-behind. Why not? Maybe there's a way to generate them into .cs files and I just don't know about it.
Now the bigger problem is that I can't use .resx resources from .xaml either. WHY?! Visual Studio 2010's designer sure doesn't see them, but again, it may be my bad.
MSDN suggests to use the UICulture tag. It does put the .baml resource in a satellite assembly, so that the assembly doesn't even contain the neutral one. But it doesn't work for an old-school neutral resource, AFAIK, a non-localized .resx needs to go into the main assembly. So if I want to use new and old-school in the same project, I can't use the UICulture tag, I need all neutral resources in the main assembly. Am I the only one who's bothered by this?
So the questions:
You can actually work with RESX files rather easily in WPF, and for localization it's the way to go.
Look at: http://www.codeproject.com/KB/WPF/WPF_Resx_Localization.aspx and Get values from *.resx files in XAML
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With