Home > Posts > HowTo: Set UI language (CurrentUICulture) in Silverlight

HowTo: Set UI language (CurrentUICulture) in Silverlight

At LvS (the opensource application of LeViS), I’ve been using this (VB.net) code to set the UI language (for example to Greek):

Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("el")

Others seem to have been using (C# – that’s why there is a trailing semicolon):

Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("el");

assuming System.Globalization and System.Threading namespaces have been imported.

However, now that I’m building ClipFlair in Silverlight (http://clipflair.codeplex.com), I noticed both GetCultureInfo and CreateSpecificCulture aren’t exposed to Silverlight. Seems one needs for example to modify their App.xaml to use new CultureInfo("el") to do something like below (see parts in bold):

 

using System.Globalization;
using System.Threading;



private void Application_Startup(object sender, StartupEventArgs e)
{
CultureInfo c = new CultureInfo("el");            
Thread.CurrentThread.CurrentCulture = c;            
Thread.CurrentThread.CurrentUICulture = c;



this.RootVisual = new MainPage();        
}

 

Alternatively you can set at each XAML page/control the “language” attribute of the “UserControl” element.

If you want to enable dynamic on-the-fly localization based on end-user selection of UI language at runtime (say via a drop-down box), checkout a nice solution (the “Localizer” one) at:

http://stackoverflow.com/questions/3992007/how-to-switch-ui-culture-of-data-binding-on-the-fly-in-silverlight

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: