【发布时间】:2012-08-09 11:07:07
【问题描述】:
我正在将一个浮点属性绑定到我的 TextBox 控件。如果我使用“en”作为我的语言首选项,那是正确的。 输入数字“1.123”被正确解析。
如果我将 mur 文化切换为“de”,则 TextBox(和 TextBlocks)中没有任何变化。仍然所有内容都用“.”格式化。
通过 WinRT 的“数字”键盘输入数字是使用“,”作为分隔符。但是在 Focus 丢失后,Training Digits 将不再是数字的一部分(并且绑定属性已更新。 所以“1,234”应该在内部解析为“1.234”。但 ist 转换为“1”。
app.xaml.cs 包含更多初始化,以确保将文化设置为正确的语言。允许的语言是 ("en" 和 "de" (*,proj file. 如果您闯入调试器,CultureInfo.CurrentCulture 会正确设置为“de”。
public App()
{
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = CultureInfo.CurrentCulture.Name;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CurrentCulture;
CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.CurrentCulture;
【问题讨论】:
-
你们如何改变文化?如果通过 Windows 更改用户的文化,您是否确保应用程序被终止然后重新启动? CultureInfo.CurrentCulture 表示文化仅在线程创建时设置。
-
我正在通过 Windows 设置语言。 App.cs 包含用于确保分配正确语言的附加设置:
标签: wpf microsoft-metro windows-runtime cultureinfo