The WPF text box responds to quite a number of editing commands. I want to eliminate the vast majority and have it respond to any text input and few editing commands like backspace & delete. I know I can handle the KeyDown event but I can't see any easy way of distinguishing between character input and editing key strokes.
You can use the Preview events. They happen before the actual key events that actually perform the work. For instance, if you want to disable the down arrow for moving up and down in text, in the PreviewKeyDownEvent
you would check 'e.Key' for the down key, and if found, and set e.Handled = true
. This effectively removes that key press from the processing. As such, KeyDown will never get called.
Using this method you can remove specific keys, or combinations of keys and modifiers (such as CTRL-C if you wanted to disable the 'copy' shortcut).