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