Magesh
Magesh

Reputation: 49

WPF - get the list of Windows 10 languages

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

Answers (1)

Tony
Tony

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":

Culture

References: https://blogs.windows.com/windowsdeveloper/2019/04/30/calling-windows-10-apis-from-a-desktop-application-just-got-easier/#eAjFgDgbqEcJZIqb.97

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: Screenshot

Upvotes: 1

Related Questions