Keith Jones
Keith Jones

Reputation: 85

How to keep keyboard focus on textbox?

Throughout the app I need to use ENTER to advance to next control (same as Tab), and I do that by using EventManager.RegisterClassHandler, KeyDownEvent for textboxes in Application_Startup. But for one particular textbox (which is the input for a barcode scanner), I want to keep the focus to allow multiple scannings. So it has to receive a number, process it, then clear the box and keep the focus for the next read. Barcode reader is automatically sending an ENTER at the end of a read. Textbox must still be able to lose focus by user's choice (like mouse clicking in another box)

Upvotes: 0

Views: 895

Answers (1)

brunnerh
brunnerh

Reputation: 184516

Explicitly handle the PreviewKeyDown on that box and set Handled to true on the event arguments. It executes before any KeyDown handlers.

Upvotes: 2

Related Questions