#642 – Focusable and IsTabStop in Combination

A control can only accept user input via the keyboard if its Focusable property is set to true.  A control can be tabbed to and accept input only if both the Focusable and IsTabStop properties are true.

This means that if Focusable is false, the IsTabStop property is ignored.

#641 – The Difference Between IsTabStop and Focusable

The Focusable property for a control indicates whether the control can receive focus, which means that the control can receive keyboard input after the user clicks on the control.

Focusable is normally set to true for controls that are designed to accept user input.

The IsTabStop property, on the other hand, indicates that a control is part of the set of controls that are visited when the user cycles focus using the Tab key.

By default, controls whose Focusable property is set to true will also have their IsTabStop property set to true.  You can change this however.  If you set IsTabStop to false, but leave Focusable set to true, the user can click on a control to give it focus, but can’t tab to the control.

#639 – Default Tab Order Is Sensible

In WPF, you can use the Tab key to cycle through all of the focusable controls in a window, changing which control currently has focus.

You normally don’t need to worry about the tab order for controls in a window or page because WPF sets the tab order to match the logical tree.  If you start an application and press the Tab key, the first control in the logical tree will receive focus.

If you then continue to press Tab, each control in the logical tree that has its IsTabStop property set will receive focus.  The order will match the logical tree, starting at the top-level parent and working in a depth-first fashion through all child controls.

In the example below, we have several nested StackPanelin a window.  The numbers indicate the effective tab order.

#623 – Focusable Property Indicates Whether a Control Can Receive Focus

All controls that derive from UIElement have a Focusable property that indicate whether or not they are allowed to have focus.  This property defaults to a value that makes sense for each type of control, given whether a control is meant to allow a user to interact with it by pressing keys.

Here’s a summary of some common user interface elements, with their default values for Focusable.

Elements that have Focusabletrue by default:

  • Button
  • Calendar
  • ComboBox
  • DataGrid
  • DatePicker
  • ListBox
  • RichTextBox
  • Slider
  • TabControl
  • TextBox
  • TreeView
  • Window

Elements that have Focusablefalse by default:

  • Canvas
  • DockPanel
  • Grid
  • Image
  • Label
  • ProgressBar
  • ScrollBar
  • Separator
  • Subclasses of Shape (Ellipse, Line, Path, Polygon, Polyline and Rectangle)
  • StackPanel
  • TextBlock
  • UniformGrid
  • Viewport3D
  • WrapPanel