WPF and Chinese Input method compatibility problem Solution

Source: Internet
Author: User

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:

    1. program crashes;
    2. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.