I want to format dates and numbers according to the "Regional format" setting the user configured in Windows 10. With WPF this was no problem. With UWP this seems to impossible without resorting to hacks.
Sample code to experiment with.
I stared a new question because the best similar one is 3 years old without an accepted answer.
The "Regional format" is a Windows setting the user can configure independent of the language and region. E.g. the user can have configured:
- Languages: English (as Windows display language), French, German
- Region: Thailand (to get regional information)
- Regional format: German (to display dates and numbers in German format)
MS seems to want us using UserProfile.GlobalizationPreferences, but this does not expose the active "Regional format". There is an MS statement "It is intentional. Microsoft is moving away from forcing applications to be in the language of the OS..." in the question mentioned above. We never had a problem creating apps in a language different from the OS. And this does not explain how to honor the users choice in an UWP app.
- UserProfile.GlobalizationPreferences.HomeGeographicRegion returns the region not the "Regional Format".
- Windows.Globalization.Language.CurrentInputMethodLanguageTag depends on the keyboard selection.
- Windows.System.UserProfile.GlobalizationPreferences.Languages(1) only
works if the user accidentally configured a "Regional format"
matching the second language.
I read all posts I could find about this and the only solution seems to be the following hack described here:
var systemLanguage = GlobalizationPreferences.Languages.First();
var regionInfo = new RegionInfo(systemLanguage);
var dtf = new DateTimeFormatter("longdate", new[] { regionInfo.TwoLetterISORegionName });
var regionInfoName = dtf.ResolvedLanguage;
var regionFormatCultureInfo = new CultureInfo(regionInfoName);
What MS seems to suggest does not work for me and my customers complain about my apps not honoring their settings.
Can someone shed some light into this? If this is an SDK bug, it should have been fixed long ago.
The built-in Calendar UWP app does honor the regional format.