Thursday, 2 May 2013

Set Regional Settings (culture) in Silverlight application.

Today I was looking at some issues with date formats, why in god's name do the american's use a different date system than everybody else?, and I ended up using the following code to set up the Regional Settings (No prizes for guessing where I work):

private void Application_Startup(object sender, StartupEventArgs e)
    this.RootVisual = new MainPage();
    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-GB");
    var root = RootVisual as  MainPage;
    if (root != null)
     root.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);

This is in the App.xaml code behind file.

Note that annoyingly, this will not work in WPF.

No comments:

Post a Comment