UWP:获取当前 CultureInfo

UWP: Get current CultureInfo

对于 UWP,根据博客条目 CultureInfo changes in UWP. Can I take GlobalizationPreferences 对 CultureInfo 进行了一些更改以正确获取 CultureInfo

public CultureInfo GetCurrentCultureInfo()
{
    return new CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0].ToString());
}

摘自 this example.

Can I take GlobalizationPreferences to get the CultureInfo correctly?

可以的,我测试了你的方法,在我身边效果很好。

I want to know the current language of the device (not region).

您还可以使用 Windows.Globalization.Language.CurrentInputMethodLanguageTag 获取当前启用的键盘布局或输入。

如果您需要的是 "correct" CultureInfo(考虑到 user/machine 区域设置的信息),那么您应该使用该博客 post 上的信息,或者更好的是,使用 GetLocaleInfoEx Win32 API 来检索它。

我已经为那篇文章写了一篇 Part 2,其中包含如何使用此 API 的完整示例。