Files
docs-desktop/dotnet-desktop-guide/framework/wpf/controls/how-to-set-focus-in-a-textbox-control.md
Andy (Steve) De George be103da07e Replace various WPF include files with content (#1335)
* net-current-v30plus-md.md

* net-current-v40plus-md.md

* tla2sharptla-ui-md.md

* tla2sharptla-uiautomation-md.md

* tla2sharptla-winclient-md.md

* tla2sharptla-xaml-md.md

* tlasharptla-ui-md.md

* tlasharptla-uiautomation-md.md

* tlasharptla-winclient-md.md

* tlasharptla-xaml-md.md

* fix warnings
2022-03-16 12:14:11 -04: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 Extensible Application Markup Language (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