如何在wpf中更改应用程序文化?

时间:2014-06-10 07:52:50

标签: c# wpf cultureinfo

这是我的代码。

double value = double.Parse(Utility.GetParamValueOrDefault(omRecord.paramList[i].value, "0"),CultureInfo.CurrentCulture);

这是我得到的错误 的出现FormatException: 输入字符串的格式不正确

我已经阅读了StackOverFlow的一些线程,说我需要将以下代码添加到我的WPF应用程序的main()中。

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

我仍然得到同样的错误,我的CurrentCulture仍然不是en-US。

2 个答案:

答案 0 :(得分:13)

试试这个

CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");

答案 1 :(得分:4)

在应用程序开始时,您可以这样设置CultureInfo

Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

如果要在运行时确定CultureInfo,请尝试以下方法:

System.Globalization.CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;

对于英语,有这个表: - )

en          en-US       English
en-029      en-029      English (Caribbean)
en-AU       en-AU       English (Australia)
en-BZ       en-BZ       English (Belize)
en-CA       en-CA       English (Canada)
en-GB       en-GB       English (United Kingdom)
en-IE       en-IE       English (Ireland)
en-JM       en-JM       English (Jamaica)
en-NZ       en-NZ       English (New Zealand)
en-PH       en-PH       English (Republic of the Philippines)
en-TT       en-TT       English (Trinidad and Tobago)
en-US       en-US       English (United States)
en-ZA       en-ZA       English (South Africa)
en-ZW       en-ZW       English (Zimbabwe)

以下是所有语言https://wiki.openstreetmap.org/wiki/Nominatim/Country_Codes

的链接