How to set different localized strings in different visual states in WP7 using Blend?

How to set different localized strings in different visual states in WP7 using Blend without any code?

I can set different non-localized strings in different visual states (although it flickers). This works, but what about localized strings?

If I change the line using data binding in Blend, Blend simply overrides the data binding in the base state, not the actual state in which I am writing.

EDIT:

This is how I localize my strings:

I have a resource file called AppPresources.resx . Then I would do it in code:

  // setting localized button title mainButton.Content = AppResources.MainButtonText; 

Then I have a GlobalViewModelLocator from the MVVM Light Toolkit with the following property for data binding.

  private static AppResources _localizedStrings; public AppResources LocalizedStrings { get { if (_localizedStrings == null) { _localizedStrings = new AppResources(); } return _localizedStrings; } } 

And in the xaml file:

 <Button x:Name="mainButton" Content="{Binding LocalizedStrings.MainButtonText, Mode=OneWay, Source={StaticResource Locator}}" ... /> 
+6
windows-phone localization mvvm expression-blend
source share
1 answer

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:

+4
source share

All Articles