Silverlight Chinese Input bug temporary solution

Source: Internet
Author: User
Tags silverlight

I encountered a problem today. The Textbox Control of Silverlight will repeat when entering Chinese characters. I checked the information online and found it a bug. There is a solution function on the Internet, which doesn't feel very comfortable to use, so I wrote one by myself, basically solving the problem and having bugs, and I was unable to adapt to the pasted data. The function is as follows:

String mlasttext = NULL;
Private void textbox_textchanged (Object sender, textchangedeventargs E)
{
Textbox TXT = sender as textbox;
If (mlasttext = NULL)
Mlasttext = "";
// Length difference
Int num = (txt. Text. Length-mlasttext. Length );
// It is not a question of Chinese Input
If (Num <= 0 | num % 2! = 0)
{
Mlasttext = TXT. text;
Return;
}
Int start = TXT. selectionstart;
// Neither
If (START-num <0)
{
Mlasttext = TXT. text;
Return;
}
String tmpstr = TXT. Text. Remove (START-Num, num );
// Not yet
If (! Tmpstr. Equals (mlasttext ))
{
Mlasttext = TXT. text;
Return;
}
Tmpstr = TXT. Text. substring (START-Num, num );
// Still not
If (tmpstr. substring (0, num/2 )! = Tmpstr. substring (Num/2 ))
{
Mlasttext = TXT. text;
Return;
}
TXT. textchanged-= new textchangedeventhandler (this. textbox_textchanged );
TXT. textchanged + = new textchangedeventhandler (this. textbox_textchanged_non );
TXT. Text = TXT. Text. Remove (txt. selectionstart-num/2, num/2 );
TXT. selectionstart = start-num/2;
Mlasttext = TXT. text;
}

Private void textbox_textchanged_non (Object sender, textchangedeventargs E)
{
Textbox TXT = sender as textbox;
TXT. textchanged-= new textchangedeventhandler (this. textbox_textchanged_non );
TXT. textchanged + = new textchangedeventhandler (this. textbox_textchanged );
}

You can assign the first event to textbox. However, there are still some shortcomings. We hope Microsoft can quickly release the official version.

 

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.