Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-set-focus-in-a-textbox-control.md
T
Pooja Poojari a606313314 US-1889327: Header fixes (#1319)
* Metadata updates for US-1889327.

* H2 edits.

* Updated column header.

* Minor edits.

* Review edits.
2022-02-28 08:53:24 -08:00

1.6 KiB

title, description, ms.date, ms.custom, dev_langs, helpviewer_keywords, ms.assetid
title description ms.date ms.custom dev_langs helpviewer_keywords ms.assetid
How to: Set Focus in a TextBox Control Learn how to use the Focus method to set focus on a Windows Presentation Foundation TextBox control. 03/30/2017 devdivchpfy22
csharp
vb
focus [WPF], setting
TextBox control [WPF], setting focus
24b61b45-dc2d-425e-9839-b017af7ab86f

How to: Set Focus in a TextBox Control

This example shows how to use the xref:System.Windows.UIElement.Focus%2A method to set focus on a xref:System.Windows.Controls.TextBox control.

Define a simple TextBox control

The following [!INCLUDETLA#tla_xaml] example describes a simple xref:System.Windows.Controls.TextBox control named tbFocusMe

[!code-xamlTextBox_MiscCode#_TextBoxFocusXAML]

Set the focus on the TextBox control

The following example calls the xref:System.Windows.UIElement.Focus%2A method to set the focus on the xref:System.Windows.Controls.TextBox control with the Name tbFocusMe.

[!code-csharpTextBox_MiscCode#_FocusTextBox] [!code-vbTextBox_MiscCode#_FocusTextBox]

See also