I have a simple text box in a WPF application.
I need to know when a character was added/deleted in the text box, which character and where it was added or deleted.
I thought about using the TextBox.KeyDown
event, but it has some problems:
- I can't know where the character was added or deleted.
- I have no idea how to determine which character was added (from the
KeyEventArgs
).
Any ideas?
You can use a "brute force" method - the text box (in winforms and I think in WPF as well) has a text changed event you can use and by comparing the text before the event and the current text you can find what character has been added or removed.
Found the solution. In WPF, the
TextBox.TextChanged
event has aTextChangedEventArgs
. In this class, there is a property namedChanges
.Here's my code:
Now I just need to wait two days to accept this answer. :)
Thanks anyway.