0 out of 2 rated this helpful - Rate this topic

FocusManager Class

Provides a set of static methods, attached properties, and events for determining and setting focus scopes and for setting the focused element within the scope.


Namespace:  System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)
public ref class FocusManager abstract sealed

The FocusManager type exposes the following members.

Public attached propertyFocusedElementDetermines whether the element this property is attached to has logical focus.
Public attached propertyIsFocusScopeDetermines whether the element this property is attached to is a focus scope.
Public methodStatic memberAddGotFocusHandlerAdds a handler for the GotFocus attached event.
Public methodStatic memberAddLostFocusHandlerAdds a handler for the LostFocus attached event.
Public methodStatic memberGetFocusedElementGets the element with logical focus within the specified focus scope.
Public methodStatic memberGetFocusScopeDetermines the closest ancestor of the specified element that has IsFocusScope set to true.
Public methodStatic memberGetIsFocusScopeDetermines whether the specified DependencyObject is a focus scope.
Public methodStatic memberRemoveGotFocusHandlerRemoves a handler for the GotFocus attached event.
Public methodStatic memberRemoveLostFocusHandlerRemoves a handler for the LostFocus attached event.
Public methodStatic memberSetFocusedElementSets logical focus on the specified element.
Public methodStatic memberSetIsFocusScopeSets the specified DependencyObject as a focus scope.
Public attached eventGotFocusOccurs when an element gets focus.
Public attached eventLostFocusOccurs when an element loses focus.
Public fieldStatic memberFocusedElementPropertyIdentifies the FocusedElement attached property.
Public fieldStatic memberGotFocusEventIdentifies the GotFocus attached event.
Public fieldStatic memberIsFocusScopePropertyIdentifies the IsFocusScope attached property.
Public fieldStatic memberLostFocusEventIdentifies the LostFocus attached event.

In Windows Presentation Foundation (WPF) there are two concepts concerning focus: keyboard focus and logical focus.

Keyboard focus pertains to the element which is currently receiving keyboard input. There can be only one element with keyboard focus. This element with keyboard focus has IsKeyboardFocused set to true. Keyboard::FocusedElement returns the element with keyboard focus.

Logical focus pertains to the FocusManager::FocusedElement within a specific focus scope.

A focus scope is a container element that keeps track of the FocusManager::FocusedElement within its scope. By default, the Window class is a focus scope as are the Menu, ContextMenu, and ToolBar classes. An element which is a focus scope has IsFocusScope set to true.

There can be multiple elements with logical focus, but there can only be one element with logical focus within a single focus scope. An element with logical focus does not necessarily have keyboard focus, but an element with keyboard focus will have logical focus. It is possible to define a focus scope within a focus scope. In this case, both the parent focus scope and the child focus scope can have a FocusManager::FocusedElement.

The following scenario illustrates how keyboard focus and logical focus change in a Windows Presentation Foundation (WPF) application that has a Window with a TextBox and a Menu which has a MenuItem. When keyboard focus changes from the TextBox to the MenuItem, the TextBox losses keyboard focus but retains logical focus for the Window focus scope. The MenuItem obtains keyboard focus and obtains logical focus for the Menu focus scope. When keyboard focus returns to the root Window, the element in Window focus scope with logical focus will obtain keyboard focus, which in this case is the TextBox. The TextBox now has keyboard focus and logical focus. The MenuItem loses keyboard focus, but retains logical focus for the Menu focus scope. 

The default value of IsFocusScope on a Window, Menu, ToolBar, and ContextMenu is true.

For more information on focus, see the Input Overview and the Focus Overview.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.