如何正确设置Silverlight中的CurrentUICulture /的CurrentCulture? [英] How to set Silverlight CurrentUICulture/CurrentCulture correctly?

查看:246
本文介绍了如何正确设置Silverlight中的CurrentUICulture /的CurrentCulture?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#中的SL5的应用程序,我期待国际化了。我发现下面的设置界面文化:

  VAR文化=新的CultureInfo(Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);
Thread.CurrentThread.CurrentUICulture =文化;
Thread.CurrentThread.CurrentCulture =文化;
 

像DatePicker的某些控件似乎捡这件事。如果我使用'D'格式化字符串格式化任何日期时间,我还是得到默认的格式为M / DD / YYYY但是。

究竟如何呢SL除preT文化,我该怎么正确设置它为整个应用程序?

感谢

更新:

找到了答案:

首先,在Application_Startup设置适当的培养物:

  VAR文化=新的CultureInfo(NL-BE);
Thread.CurrentThread.CurrentUICulture =文化;
Thread.CurrentThread.CurrentCulture =文化;
 

的关键因素却是要增加以下强制RootVisu​​al的文化/语言:

  VAR根= RootVisu​​al的页面;
如果(根!= NULL)
{
    root.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);
}
 

解决方案

编辑:更新的信息@Rumble发现

您需要做的是这样的将其应用到你的UI对象也是如此。

首先设置相应的文化,当你的应用程序加载了。

  Thread.CurrentThread.CurrentCulture =新的CultureInfo(EN-IN);
Thread.CurrentThread.CurrentUICulture =新的CultureInfo(EN-IN);
 

接下来,您需要设置XML语言属性。

对于Silverlight的

  VAR根= RootVisu​​al的页面;
如果(根!= NULL)
{
    root.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name);
}
 

对于WPF

  FrameworkElement.LanguageProperty.OverrideMetadata(typeof运算(FrameworkElement的),新FrameworkPropertyMetadata(
            XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
 

您可以找到WPF的这里

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.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;

Some controls like the DatePicker seem to pick this up. If I format any datetime by using the 'd' format string, I still get the default format "M/dd/yyyy" however.

Exactly how does SL interpret culture and how can I set it correctly for the entire application?

Thanks

UPDATE:

Found the answer:

First of all, set the appropriate cultures in the Application_Startup:

var culture = new CultureInfo("nl-BE");
Thread.CurrentThread.CurrentUICulture = culture;
Thread.CurrentThread.CurrentCulture = culture;

The key element however is to add the following to force the RootVisual's culture/language:

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

解决方案

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.

这篇关于如何正确设置Silverlight中的CurrentUICulture /的CurrentCulture?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆