Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect system language change in WPF

Tags:

c#

.net

wpf

We can use following code to know when the system language change in Windows Form - Form.InputLanguageChanged:

string _language = "";
InputLanguageChanged += new InputLanguageChangedEventHandler( (sender, e) =>
{
      language = InputLanguage.CurrentInputLanguage.LayoutName;
});

What is WPF equivalent of Form.InputLanguageChanged?

like image 343
Hossein Mobasher Avatar asked Sep 07 '11 22:09

Hossein Mobasher


1 Answers

You can use the code as follow to detect keyboard language change in WPF

string language = "";
System.Windows.Input.InputLanguageManager.Current.InputLanguageChanged += 
       new    InputLanguageEventHandler((sender, e) =>
{
   language = e.NewLanguage.DisplayName;
}); 

Note: there is no need to detect system UI language change as it requires logoff/logon which in turn will force all applications to restart (Check Hans Passant comment for How To Detect Language Changes While Runtime ? (C#)

like image 77
Moein Hosseini Avatar answered Oct 22 '22 03:10

Moein Hosseini