See You at TechEd

I’ll Be at TechEd North America in Houston next week (12-15 May, 2014).  If you’re a fan of the 2,000 Things blogs and will be in Houston, look me up.  (E.g. DM @spsexton on Twitter).  We can go grab a beer and sing the praises of C#, WPF and all things .NET.

#1,068 – Most Controls Can Get Keyboard Focus

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.

1068-001

1068-002

1068-003

Advertisement