Export (0) Print
Expand All
Expand Minimize

UIElement3D::Focus Method

Attempts to set the logical focus on this element.

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

public:
virtual bool Focus() sealed

Return Value

Type: System::Boolean
true if both logical and keyboard focus were set to this element; false if only logical focus was set.

Implements

IInputElement::Focus()

To be focusable, Focusable and IsEnabled must both be true.

Even if an element is focusable and enabled, event handling within a specific tree, (such as for a composite control) might respond to the preview focus events by not allowing focus there, thus this method would return false.

If calling Focus returns true, IsKeyboardFocused and IsKeyboardFocusWithin are also true.

If the related properties are not already true, when you call Focus, one or more of the following events are raised in the following order: PreviewLostKeyboardFocus, PreviewGotKeyboardFocus (source is the new focus target), IsKeyboardFocusedChanged, IsKeyboardFocusWithinChanged, LostKeyboardFocus, GotKeyboardFocus (source is the new focus target).

In order for this call to be successful, some other element in the application needed to have focus previously.

Focus in general is governed by two separate concepts: keyboard focus and logical focus, which are not always identical. This method sets the logical focus, and also attempts to set the keyboard focus. There is no programmatic means to set keyboard focus specifically, this happens due to user input. For more information, see Input Overview.

Focus is introduced in the .NET Framework version 3.5. For more information, see .NET Framework Versions and Dependencies.

.NET Framework

Supported in: 4, 3.5 SP1, 3.0 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

ADD
Show:
© 2014 Microsoft