views:

61

answers:

2

I have a WPF textbox, and perform the following actions

  1. Enter text as "12345"
  2. Move cursor between 3 and 4 (using arrow or mouseclick)
  3. Enter 0 (so Text is now "123045")

Which event/eventargs can tell me that 0 was typed at location 4. I need to know this at Preview level so that I can reject the character 0 based on the prefixed and suffixed digits.

+1  A: 

You can use the PreviewTextInput event. (see here for a complete example)

Goblin
PreviewTextInput doesnt tell me the position at which the new character will be typed.
Nitin Chaudhari
+1  A: 

In PreviewTextInput event you can use the TextBox's CaretIndex property to know the location where input is being typed.

Nitin Chaudhari