Text field value changed

Is it possible to find out if any of the text field values ​​in the application has changed. I have about 30 text fields, and I want to run part of the code only if any of the values ​​of the text fields has changed from 30. Is there a way I can know this.

+3
source share
5 answers

Each text box will raise an event TextChangedwhen the content changes. However, this requires a subscription to each event.

The good news is that you can sign up for an event the same way several times. The handler has a parameter senderthat you can use to determine which of the 30 text fields the event actually raised.

You can also use GotFocus and LostFocus to track actual changes. You need to keep the original value on GotFocus, and then compare with the current value on LostFocus. This turns around the problem of two events TextChangedthat cancel each other out.

+7
source

TextBox TextChanged. . , . , , .

+2

. load/constructor. XAML

this.AddHandler(TextBox.TextChangedEvent, new TextChangedEventHandler(TextChanged));
private void TextChanged(object Sender, TextChangedEventArgs e)
{
    //ToDO (use sender to identify the actuale text from where it fired }
}
+1

, , , .

bool bChanged = false;

In the TextChanged event handler of each control (actually the same for each) I put

bChanged = true;

If necessary, I can do some processing and set bChanged to false.

+1
source

You can also just do this:

In your constructor:

MyTextBox.TextChanged += new TextChangedEventHandler( TextChanged );

And then this method:

private void TextChanged(object Sender, TextChangedEventArgs e){
            //Do something
        }
+1
source

Source: https://habr.com/ru/post/1740048/


All Articles