Detecting if IME (Input Method Editor) is active in Silverlight

I was able to resolve the issue in both the WPF and Silverlight frameworks. The issue was caused by the fact that by handling the TextBox Text while a IME is inputting symbols that Text was making the IME itself change its input which it looks like is not handled gracefully by the Windows OS and was causing a CLR exception.

What I did was:

In the WPF framework as mentioned I used the static InputMethod.Current.ImeState value to determine if IME is active and if it was with On value I skipped reverting the TextBox Text property in its TextChanged event.

In the Silverlight framework I use a combination of the TextInputStart, TextInputUpdate events and a local private field to store if IME was detected. The TextInputUpdate event is only triggered if IME is active and used as input and the TextInputStart is always triggered. What I did was:

  1. Created a bool IsImeActive = false; filed
  2. Hook to the TextInputStart event of the TextBox
  3. In that event set the IsImeActive field to False
  4. Hook to the TextInputUpdate event of the TextBox
  5. In that event set the IsImeActive field to True
  6. Finally in the TextChanged event add a condition that checks the IsImeActive field and if it is False run the logic which handles (reverses) the input.

Hope this is helpful.