C # When TextBox.Text.Length <TextBox.SelectionStart

While implementing a Behavior for a TextBox in WPF, I saw many examples that use the PreviewTextInput event to handle new input. Some examples (like techqa.info ) have a condition that I don't understand:

if (textBox.Text.Length < textBox.SelectionStart)
    text = textBox.Text;

      

From an external point of view, it is not possible for the start of the selection to be greater than the length of the text in the TextBox. At best, it might be at the end of the text. Since the start of the selection is zero-based, the length and start of the selection must be the same. Maybe this condition handles a special case?

+3


source to share





All Articles