#309 – Keyboard Focus vs. Logical Focus
May 27, 2011 1 Comment
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.
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?