区域格式在 Windows Phone Silverlight 堆栈中行为正确(恕我直言),但在 WinRT 堆栈中行为不正确(仍然是恕我直言)。自 Windows 8.0 以来,它一直表现不佳,这里对此问题进行了长时间的讨论:WinRT apps and Regional settings. The correct way to format dates and numbers based on the user's regional settings?
我最近也写了一篇关于这个问题的博文:http://mikaelkoskinen.net/winrt-xaml-misbehave-still-in-windows-81/
博客文章还包含一个似乎可以正常工作的解决方法:您可以将 Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride 设置为用户的区域格式,以使事情更好地工作。
因此,希望 App.xaml.cs 的构造函数中的以下代码证明是有用的:
public App()
{
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = Windows.System.UserProfile.GlobalizationPreferences.HomeGeographicRegion;
this.InitializeComponent();
this.Suspending += this.OnSuspending;
}
更新为替代版本
另一种选择是使用 GlobalizationPreferences.Languages-array。例如:
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = Windows.System.UserProfile.GlobalizationPreferences.Languages[1];
只需确保检查数组中实际上有超过 1 种语言即可。
这是设置 PrimaryLanguageOverride 后它在应用中的外观:
this.DateText.Text = DateTime.Now.ToString("D");
更新了屏幕截图
在 Windows Phone 8.1 中,如果您通过设置更改区域格式,所选的区域格式将被添加为第二语言。至少这是 8.1 模拟器的工作方式。因此,当我从头开始启动模拟器并更改区域设置时:
然后如果我重新启动手机,所选区域已添加为第二语言:
现在 Windows.System.UserProfile.GlobalizationPreferences.Languages 包含我选择的区域格式。