Files
docs-desktop/dotnet-desktop-guide/framework/wpf/advanced/how-to-detect-when-the-enter-key-pressed.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

1.8 KiB

title, description, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title description ms.date dev_langs helpviewer_keywords ms.assetid
How to: Detect When the Enter Key Pressed Detect when the Enter key is selected on the keyboard in Windows Presentation Foundation. This example consists of XAML and a code-behind file. 03/30/2017
csharp
vb
Enter key [WPF], detecting
keys [WPF], Enter
a66f39d2-ef4a-43a5-b454-a4ea0fe88655

How to: Detect When the Enter Key Pressed

This example shows how to detect when the xref:System.Windows.Input.Key.Enter key is pressed on the keyboard.

This example consists of a [!INCLUDETLA#tla_xaml] file and a code-behind file.

Example

When the user presses the xref:System.Windows.Input.Key.Enter key in the xref:System.Windows.Controls.TextBox, the input in the text box appears in another area of the [!INCLUDETLA#tla_ui].

The following XAML creates the user interface, which consists of a xref:System.Windows.Controls.StackPanel, a xref:System.Windows.Controls.TextBlock, and a xref:System.Windows.Controls.TextBox.

[!code-xamlkeydown#KeyDownUI]

The following code behind creates the xref:System.Windows.UIElement.KeyDown event handler. If the key that is pressed is the xref:System.Windows.Input.Key.Enter key, a message is displayed in the xref:System.Windows.Controls.TextBlock.

[!code-csharpkeydown#KeyDownSample] [!code-vbkeydown#KeyDownSample]

See also