#309 – Keyboard Focus vs. Logical Focus

In WPF, there are two types of focus–keyboard focus and logical focus.

If an element has keyboard focus, it is the element that can currently receive input from the keyboard.  Only a single element in an entire application can have keyboard at any given time.

An element has logical focus if it is the element within a focus scope that has focus.  The idea is that WPF keeps track of one or more groups of controls, each of which makes up a focus scope.  Within each focus scope, a single control can have logical focus.  This allows WPF to remember the control that last had focus in a group of controls and give the keyboard focus back to the proper control when a group of controls becomes active again.

An element that has keyboard focus always has logical focus.  An element that has logical focus may not have keyboard focus.

Advertisement

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #309 – Keyboard Focus vs. Logical Focus

  1. Eric Ouellet says:

    Thanks a lot. Extremely useful. There is one think that I was wondering, I have a Grid or a Canvas with 2 childs: TextBox and Line(focusable – onClick through behavior). When I change focus with click, everything seems ok. When I use tab, a little border indicating the control with keyboard focus is highlighting either the Grid or the Line (when into a Canvas). How to get rid of the keyboard highlight?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: