Problem
One of the biggest problems I discovered when I was programming with WPF was the compatibility of WPF with Chinese input methods.
There are probably two types of problems:
- program crashes;
- Unable to switch input method.
In the author's environment has not encountered the collapse of the situation, only the latter situation. But I think the reasons for these two situations should be the same.
The specific behavior is: when you enter Chinese characters in a Textbox control in WPF , we need to switch the IME first. After switching the status bar display switch success, and start typing pinyin, but found that the phonetic input directly into the textbox box, the situation seems to have not been successfully switched.
What's more, the situation is not absolute, and restarting the program and switching the IME multiple times can become normal.
My environment for Win10 + VS2012 + WPF4.5 + QQ Pinyin Input Method 5.1
Solution Solutions
Since this problem exists only in the Chinese input environment, the foreigner should not have this problem, so there is no solution found in Stack Overflow .
After encountering this problem, I did not resolve it for a long time, and later I saw a WindowsFormsHost control, the WinForm host, in WPF . So I think, since This problem does not exist in WinForm, then the WinForm textbox is replaced by this host as the WPF textbox Is it possible to solve this problem?
After trying it, I found that it was really possible. The specific steps are:
1, add a WindowsFormsHost control in the window layout, set Name(here is host);
2. Add a WinForm Textbox in the host with the code:
New System.Windows.Forms.TextBox ();
Insufficient
Of course, this scheme is not perfect, such as the following points:
poor performance and appearance
One of the biggest benefits of WPF compared to WinForm is that the interface is more radiant and fluid. This benefit is lost when using this scheme, but the Textbox generally does not require effects such as background images or translucency, so there is little impact here.
Portability
Because this scenario mixes two GUI frameworks, it cannot be used in a WPF-only-enabled environment.
WPF and Chinese Input method compatibility problem Solution