Keyboard focus vs logical focus in WPF

别等时光非礼了梦想. 提交于 2019-12-18 11:46:07

问题


What is the difference by Keyboard focus and logical focus in WPF? and how WPF focus is different from the focus in winform ?


回答1:


see Focus Overview

Keyboard focus refers to the element that is currently receiving keyboard input. There can be only one element on the whole desktop that has keyboard focus. In WPF, the element that has keyboard focus will have IsKeyboardFocused set to true. The static property FocusedElement on the Keyboard class gets the element that currently has keyboard focus.

Logical focus refers to the FocusManager.FocusedElement in a focus scope. A focus scope is an element that keeps track of the FocusedElement within its scope. When keyboard focus leaves a focus scope, the focused element will lose keyboard focus but will retain logical focus. When keyboard focus returns to the focus scope, the focused element will obtain keyboard focus. This allows for keyboard focus to be changed between multiple focus scopes but ensures that the focused element in the focus scope regains keyboard focus when focus returns to the focus scope.




回答2:


I found a good series of blog posts on WPF focus.

  1. Part1ItsBasicallyFocus

  2. Part2ChangingWPFFocusInCode

  3. Part3ShiftingFocusToTheFirstAvailableElementInWPF

They are all good to read, but the 1st part specifically deals with logical vs keyboard focus. The 3rd part shows a good way to set focus to a UI element in a UserControl.



来源:https://stackoverflow.com/questions/1320816/keyboard-focus-vs-logical-focus-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!