WPF TextChanged event causes a dead loop, event-triggered loop issue

Source: Internet
Author: User

1. Example:

Description: When the text content of a TextBox control changes, the TextChanged event is triggered and is immediately executed synchronously.

Based on this feature, a global variable identifier is set, CHANGETXTB, if the TXTB is being modified, the Txt_textchanged event content is not executed.

This will solve the problem of the death cycle caused by the TextChanged event.

//bitPrivate voidTxtb_textchanged (Objectsender, Textchangedeventargs e) {    if(CHANGETXTB)//If the TXTB is currently being modified, the following code does not execute        return; Try    {        if(string. IsNullOrEmpty (TXTB. Text) {Txtb.            Focus (); return; }        DoubleNumber =Double. Parse (TXTB.        Text); Txtb.text= (Number/8.0).    ToString (); }    Catch(Exception ex) {ShowError (ex).    Message); }}//Identify TXTB dialog box is modifying dataPrivate BOOLCHANGETXTB =false;//bytesPrivate voidTxtb_textchanged_1 (Objectsender, Textchangedeventargs e) {Label1. Content="";Try{if(string.    IsNullOrEmpty (Txtb.text)) {txtb.focus (); return;}//identity is modifying TXTBCHANGETXTB =true;//The gigabyte transformation is a uniform modification of other contentDoubleNumber =Double. Parse (Txtb.text); Txtb. Text= (number *8). ToString ();//when the Text property is modified, the txtb_textchanged is immediately triggered synchronouslyTxtkb.text = (number/1024.0). ToString (); Txtmb.text= (Number/1024.0/1024.0). ToString (); Txtgb.text= (Number/1024.0/1024.0/1024.0). ToString (); Txttb.text= (Number/1024.0/1024.0/1024.0/1024.0). ToString ();}Catch(Exception ex) {ShowError (ex). Message);}//Identity End Modification TXTBCHANGETXTB =false;}

WPF TextChanged event causes a dead loop, event-triggered loop issue

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.