Reputation: 49
In C# WPF, how to get the list of Windows 10 available languages, I need this to load the dropdown list in WPF.
I see this is available in UWP but I don't find one for WPF. https://social.msdn.microsoft.com/Forums/vstudio/en-US/e2954327-fe9e-484e-95bf-e6b1e3f32858/uwp-howto-show-language-list-with-installed-input-languages-at-the-top?forum=wpdevelop
Upvotes: 1
Views: 722
Reputation: 17657
You can add this NuGet Package Microsoft.Windows.SDK.Contracts so you can access Windows.System.UserProfile.GlobalizationPreferences from WPF.
Then you can call this code from your WPF Application:
var languages = Windows.System.UserProfile.GlobalizationPreferences.Languages.ToList();
It will contain a list of string of languages that are preferred by the user, in order of preference. On my machine, it returns "pt-BR":
Note that it requires default package management format set to PackageReference, and NuGet 4.0 or higher.
You can do it on Visual Studio 2019 using the context menu:
Upvotes: 1