I have a TextChanged event for my WPF TextBox as follows:
private void textMatch_TextChanged(object sender, TextChangedEventArgs e)
{
var m = e.Changes;//here I can see e.Changes has what I'm looking for
//do some other stuff here.
}
However, what I want to do is to check the length of text that was added. Apparently, e.Changes contains that value but I can’t figure out a way to find it out programmatically neither could I find any example online.
My current way of checking this is by storing the current length each time text is changed and making sure the new length only increases by 1 but It’s sorta like hacking to me.
Has anyone tried this before? How do I find out the length of the added text using the TextChangedEventArgs? Thanks.
What you’re looking for is how to extract the
TextChangeobject from thee.ChangesTextChange collection. The following should work:However, if you want something that looks more specific you could use:
Since
e.Changesas far as I know at the moment will always contain a singleTextChangeitem, I guess it will always be the first even in future implementations of the WPF TextBox.For Non-Linq implementation which seems really unnecessary to me you can use the following bulky code: