Silverlight: How to get before changed value of textbox when textchange event fired
-
30-04-2021 - |
Вопрос
I have a textbox, when textchange event fired, I want to compare the old value with the changed value.
How to get the old value?
Решение
Register the KeyDown-Event of the TextBox. This is event is raised when a Key is pressed and before the TextChanged-Event of the TextBox is raised.
In this event, you can get the current Text by calling the Text-Property of the TextBox.
TextBox myTextBox = new TextBox();
myTextBox.KeyDown += KeyDownOnMyTextBox;
myTextBox.TextChanged += TextChangedOnMyTextBox;
string currentText = string.Empty;
string newText = string.Empty;
private void KeyDownOnMyTextBox(object sender, KeyEventArgs e){
currentText = myTextBox.Text;
}
private void TextChangedOnMyTextBox(object sender, TextChangedEventArgs e){
newText = myTextBox.Text;
}
Другие советы
You are going to have to make a note of the value each time this event is fired or you assign it a value.
Then you can compare it.
Не связан с StackOverflow