13

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?

CharithJ
  • 46,289
  • 20
  • 116
  • 131
Hossein Mobasher
  • 4,382
  • 5
  • 46
  • 73

2 Answers2

11

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#)

Community
  • 1
  • 1
Moein Hosseini
  • 4,309
  • 15
  • 68
  • 106
  • Could the InputLanguageManager be used to set the input language on the OSK? We are developing an app for a touch screen in WPF/.NET 4 and need to have the OSK open up in the correct language... We are changing the current thread culture on the fly as well, but we're using a custom localization solution. The only piece left is to get the keyboard to sync up, and if I can't get that working we will have to look into third party keyboards... – Valerie Sep 22 '11 at 14:54
3

Hope this helps. You have to use InputLanguageManager.InputLanguageChanging Event which occurs when a change of input language is initiated. It should be as below.

InputLanguageManager.Current.InputLanguageChanged += new InputLanguageEventHandler(Current_InputLanguageChanged);

And here is more details that I found interesting. WPF Localization - On-the-fly Language Selection

CharithJ
  • 46,289
  • 20
  • 116
  • 131