Key Property
Collapse the table of content
Expand the table of content

KeyGesture.Key Property

Gets the key associated with this KeyGesture.

Namespace: System.Windows.Input
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:

public Key Key { get; }
/** @property */
public Key get_Key ()

public function get Key () : Key

You cannot use this property in XAML.

Property Value

The key associated with the gesture. The default value is None.

In most cases, a KeyGesture must be associated with one or more ModifierKeys. The exceptions to this rule are the function keys and the numeric keypad keys, which can be a valid KeyGesture by themselves.

The following example binds the Close command to a KeyGesture using a KeyBinding. In XAML, the KeyBinding properties Key and Modifiers is converted into a KeyGesture.

<KeyBinding Modifiers="Alt"
            Command="ApplicationCommands.Close" />

KeyGesture CloseCmdKeyGesture = new KeyGesture(
    Key.L, ModifierKeys.Alt);

KeyBinding CloseKeyBinding = new KeyBinding(
    ApplicationCommands.Close, CloseCmdKeyGesture);


Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

© 2015 Microsoft