How to set Silverlight CurrentUICulture/CurrentCulture correctly?

前端 未结 2 1918
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 07:07

I\'m working on a SL5 app with C# and I\'m looking to internationalize it. I found the following to set the UI culture:

var culture = new CultureInfo(Thread.         


        
2条回答
  •  温柔的废话
    2020-12-19 07:27

    Edit: Updated with the information that @Rumble found.

    You need to do it like this to apply it to your UI objects as well.

    First set the appropriate cultures when your application is loading up.

    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-IN");
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-IN");
    

    Next you need to set the XML Language property.

    For Silverlight

    var root = RootVisual as Page;
    if (root != null)
    {
        root.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);
    }
    

    For WPF

    FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
                XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
    

    You can find an explanation for WPF here.

提交回复
热议问题