#1,068 – Most Controls Can Get Keyboard Focus
May 8, 2014 1 Comment
In WPF, controls that a user interacts with are typically able to get keyboard focus. (Focusable property is true). This includes controls that supported text-based input, like the TextBox. But it also includes controls that the user typically interacts with using the mouse, rather than the keyboard.
Controls that cannot get keyboard focus are ones like the Label that the user does not interact with.
For example, a user will typically use only the mouse when interacting with a Button or a CheckBox, but both of these controls can get keyboard focus. This is because the user can also interact with these controls using the keyboard. (E.g. Enter key to “click” a Button, or Spacebar to toggle a CheckBox).
The example below uses code to detect which control has focus. Note that as we tab through the controls, the TextBox controls get focus, as well as the Button and the CheckBox.