2

我们使用以下代码在操作系统上设置输入语言:

InputLanguageManager.Current.CurrentInputLanguage = initialCulture;

它适用于开发电脑,但在生产电脑上Current为空。

InputLanguageManager.Current 实现如下:

public static InputLanguageManager Current
{
  get
  {
    if (InputMethod.Current.InputLanguageManager == null)
      InputMethod.Current.InputLanguageManager = new InputLanguageManager();
    return InputMethod.Current.InputLanguageManager;
  }
}

InputMethod.Current 实现如下:

public static InputMethod Current
{
  get
  {
    InputMethod inputMethod = (InputMethod) null;
    Dispatcher dispatcher = Dispatcher.FromThread(Thread.CurrentThread);
    if (dispatcher != null)
    {
      inputMethod = dispatcher.InputMethod as InputMethod;
      if (inputMethod == null)
      {
        inputMethod = new InputMethod();
        dispatcher.InputMethod = (object) inputMethod;
      }
    }
    return inputMethod;
  }
}

MSDN 说 InputMethod 可以为null,当没有活动的输入法时

我不明白。还有其他人吗?

4

0 回答 0