What you need to do is very close to what you are already doing. First define a class named Resources.cs with the following contents
public class Resources { private static AppResources resources = new AppResources(); public AppResources LocalizedStrings { get { return resources; } } }
This allows us to instantiate your resource file in XAML. To do this, open App.xaml and add the following
<Application.Resources> <local:Resources x:Key="Resources" /> </Application.Resources>
Now that you need to do the bindings in your XAML, you do it like this:
<Button Content="{Binding LocalizedStrings.MainButtonText, Source={StaticResource Resources}}" />
What you will notice is that it does not work in Blend, yet . To make it work in Expression Blend, add the following file: DesignTimeResources.xaml to the properties folder and add the following content
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:YourNameSpace"> <local:Resources x:Key="Resources" /> </ResourceDictionary>
Now you press F6 in Visual Studio to recompile, and voila - your localized strings are available in Expression Blend!
Real example from one of my projects:
Claus jรธrgensen
source share