11

Is there any way to catch the Up/Down arrow keys in a WPF TextBox (System.Windows.Controls.Textbox) and allow them to alter the text? I've read about overiding the ProcessCmdKey method for a Windows Forms TextBox (System.Windows.Forms.TextBox), and it worked fine, but that TextBox is not nearly as flexible as the WPF one. Is there a similar method to accomplish this without having to use the old Windows Forms TextBox?

For my example, I have a TextBox that has a numeric text-mask. I want to be able increase/decrease the numeric value by using the up and down arrow keys.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Randy Cleary
  • 705
  • 3
  • 11
  • 25
  • I like how this question was asked, specifically mentioning that Windows.Forms was NOT wanted/needed. The answer below was spot on. – Zyre Nov 28 '15 at 03:57

1 Answers1

30

You could add event handlers to KeyUp and/or KeyDown, if that doesn't get what you need, using PreviewKeyUp and/or PreviewKeyDown should.

John Gardner
  • 24,225
  • 5
  • 58
  • 76