如何更改 wpf 中的应用程序文化?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24135675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change Application Culture in wpf?
提问by Gilad
Here is my code.
这是我的代码。
double value = double.Parse(Utility.GetParamValueOrDefault(omRecord.paramList[i].value, "0"),CultureInfo.CurrentCulture);
this is the error i'm getting FormatException: Input string was not in a correct format
这是我收到FormatException的错误 :输入字符串的格式不正确
i have read some threads of StackOverFlow saying i need to add into main() of my WPF application the following code.
我已经阅读了 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)));
i still get the same error and my CurrentCulture is still not en-US.
我仍然遇到同样的错误,我的 CurrentCulture 仍然不是美国。
回答by Yuliam Chandra
try this
尝试这个
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
CultureInfo.DefaultThreadCurrentUICulture = new CultureInfo("en-US");
回答by daniele3004
At the start of your application you can set CultureInfo in this way
在您的应用程序开始时,您可以通过这种方式设置 CultureInfo
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
If you want to determine the CultureInfo at runtime try this:
如果你想在运行时确定 CultureInfo 试试这个:
System.Globalization.CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
For English language there is this table :-)
对于英语,有这张表:-)
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)
And here is a link for all languages https://wiki.openstreetmap.org/wiki/Nominatim/Country_Codes
这是所有语言的链接https://wiki.openstreetmap.org/wiki/Nominatim/Country_Codes

