Control.Focus method

Expand Minimize
1 out of 4 rated this helpful - Rate this topic

Attempts to set the focus on the control.

Syntax


public bool Focus(
  FocusState value
)

Parameters

value

Type: FocusState

Specifies how focus was set, as a value of the enumeration.

Return value

Type: System.Boolean [.NET] | Platform::Boolean [C++]

true if focus was set to the control, or focus was already on the control. false if the control is not focusable.

Remarks

You can't remove focus from a control by calling this method with FocusState.Unfocused as the parameter. This value is not allowed and causes an exception. To remove focus from a control, set focus to a different control.

You typically pass FocusState.Programmatic as the parameter to indicate the control obtained focus through a deliberate call to the Focus method. For example, if clicking an "Edit" button causes focus to be set on a TextBox, use the Programmatic focus state.

Pass FocusState.Pointer if you’re setting focus as the direct result of a pointer interaction. Pass FocusState.Keyboard as the parameter if you’re setting focus as a result of a keyboard interaction, like a tab sequence or key press. For example, if you’re implementing an ItemsControl and handle key presses to let the user move focus between items in the control, use the Keyboard focus state when you call Focus in your key press handler.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.winmd

See also

Control
Control.FocusState
UIElement.GotFocus
UIElement.LostFocus
Control.OnGotFocus
Responding to keyboard input
Implementing keyboard accessibility
Responding to the appearance of the on-screen keyboard sample

 

 

Build date: 3/12/2013

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.