KeyGesture Constructor (Key)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Initializes a new instance of the KeyGesture class with the specified Key.

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

public KeyGesture(
	Key key
)

Parameters

key
Type: System.Windows.Input.Key

The key associated with this gesture.

Exception Condition
InvalidEnumArgumentException

key is not a valid Key.

NotSupportedException

key is not a valid KeyGesture.

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 shows how to use this constructor to create a KeyGesture and associate it with a KeyBinding. The KeyBinding is then added to the InputBindingCollection of a Window.

KeyGesture OpenCmdKeyGesture = new KeyGesture(Key.F12);
KeyBinding OpenKeyBinding = new KeyBinding(
    ApplicationCommands.Open,
    OpenCmdKeyGesture);

this.InputBindings.Add(OpenKeyBinding);

.NET Framework
Available since 3.0
Return to top
Show: