Current Culture is wrong in WinRT

荒凉一梦 提交于 2019-12-12 09:56:51

问题


I am trying to format the datetime value using Current Culture in WinRT. But CurrentCulture property not seems to respect the System Culture.

I tried the following two properties,

System.Globalization.CultureInfo.CurrentCulture.DisplayName
System.Globalization.CultureInfo.CurrentUICulture.DisplayName

Both gives English (United States) even though I change the region in Control Panel. But this works perfectly fine for WPF. What am I doing wrong?


回答1:


WinRT uses APIs exposed in Windows.Globalisation namespace. Have a look at ApplicationLanguages class

http://msdn.microsoft.com/en-us/library/windows/apps/hh972395.aspx

This class exposes Languages, ManifestLanguages and PrimaryLanguageOveride properties




回答2:


To get the InvariantCulture settings we can use,

"ApplicationLanguages.PrimaryLanguageOverride = CultureInfo.InvariantCulture.TwoLetterISOLanguageName;"

This worked for me.




回答3:


Modern applications make use of the user language list to determine what the default application language should be and the application language is used to initialize the CurrentCulture and CurrentUICulture. Desktop apps (wpf) initialize these to the user's default UI language and locale.

One of two things is happening: your application is being built with a limited set of language resources that has en-US as the default and you do not include any of these languages in your user language list or en-US is the first language in your user language list for which you have resources in your app.



来源:https://stackoverflow.com/questions/15087075/current-culture-is-wrong-in-winrt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!