Eric's Blog

Day to day experience in .NET
Welcome to Blogs @ IRM Sign in | Join | Help
 Search

Disclaimer

The content of this site is my own personal opinion and does not in any way represent my employer, it's subsideries or affiliates. These postings are provided "AS IS" with no warranties, and confer no rights.

This Blog

More Localizing in Silverlight

I blogged about localizing a Silverlight UI here, and in that post I described how to create a StringFormatValueConvert. What I have totally missed though is that one of the new features of data binding in Silverlight 4 is support for StringFormat (together with FallbackValue and TargetNullValue), but when changing my code to use that I was back to getting US English formatting. What is happening?

First I discovered that the UICulture property was set to “en-US” instead of “sv-SE” ad Culture was. I’m not sure why they are different, but that was easily solved by setting UICulture in when the Application is created. To my surprise that wasn’t enough. So now I really started to wonder what is happening? After searching a while I found this blog post by Rick Strahl about WPF Binding and Current Culture Formatting. As he describes there all WPF/Silverlight elements includes a Language property which does not default to Culture or UICulture! (Who did that design choice?) So the solution is almost as in Rick’s post for Silverlight to with a small modification and unfortunately you can’t do it by overriding the metadata in application startup since that seems to be missing in Silverlight. I therefore use this before InitializeComponent in my main page:

public partial class MainPage : UserControl
{
    public MainPage()
    {
        this.Language = System.Windows.Markup.XmlLanguage.GetLanguage(System.Globalization.CultureInfo.CurrentCulture.ToString());

        InitializeComponent();
    }
}
Published den 9 maj 2010 09:29 by ericqu
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems