I need to disable Keyboard Input for all UI elements except one or 2 exceptions.
Thing is, I need the arrow keys for controlling so I added a KeyEventHandler on the MainWindow level and added another for UI Elements like Tab Items, Textbox so that they ignore the Input when they got the focus. I ended up with a pretty buggie control. I still can browse e.g. thru tab items, the control event sometimes doesn't fire. I need a more reliable way to do this..
Any suggestions are appreciated!
The arrow keys are not considered input keys by default. Therefore they still scroll through the controls on the window. To change this behavior you can subscribe to the
PreviewKeyDown
event (http://msdn.microsoft.com/en-us/library/system.windows.uielement.previewkeydown.aspx) and setPreviewKeyDownEventArgs.IsInputKey = true;
, see http://msdn.microsoft.com/en-us/library/system.windows.forms.previewkeydowneventargs.isinputkey.aspx. Then the arrow keys will also invoke other key event handlers asKeyDown
.