Keyboard focus vs logical focus in WPF

前端 未结 2 537
臣服心动
臣服心动 2020-12-29 06:18

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

相关标签:
2条回答
  • 2020-12-29 06:45

    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.

    0 讨论(0)
  • 2020-12-29 07:00

    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.

    0 讨论(0)
提交回复
热议问题