Rediger

Del via


KeyGesture Constructors

Definition

Initializes a new instance of the KeyGesture class.

Overloads

KeyGesture(Key)

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

KeyGesture(Key, ModifierKeys)

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

KeyGesture(Key, ModifierKeys, String)

Initializes a new instance of the KeyGesture class with the specified Key, ModifierKeys, and display string.

KeyGesture(Key)

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

public:
 KeyGesture(System::Windows::Input::Key key);
public KeyGesture (System.Windows.Input.Key key);
new System.Windows.Input.KeyGesture : System.Windows.Input.Key -> System.Windows.Input.KeyGesture
Public Sub New (key As Key)

Parameters

key
Key

The key associated with this gesture.

Exceptions

key is not a valid Key.

key is not a valid KeyGesture.

Examples

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);
Dim OpenCmdKeyGesture As New KeyGesture(Key.F12)
Dim OpenKeyBinding As New KeyBinding(ApplicationCommands.Open, OpenCmdKeyGesture)

Me.InputBindings.Add(OpenKeyBinding)

Remarks

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.

See also

Applies to

KeyGesture(Key, ModifierKeys)

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

public:
 KeyGesture(System::Windows::Input::Key key, System::Windows::Input::ModifierKeys modifiers);
public KeyGesture (System.Windows.Input.Key key, System.Windows.Input.ModifierKeys modifiers);
new System.Windows.Input.KeyGesture : System.Windows.Input.Key * System.Windows.Input.ModifierKeys -> System.Windows.Input.KeyGesture
Public Sub New (key As Key, modifiers As ModifierKeys)

Parameters

key
Key

The key associated with the gesture.

modifiers
ModifierKeys

The modifier keys associated with the gesture.

Exceptions

modifiers is not a valid ModifierKeys

-or-

key is not a valid Key.

key and modifiers do not form a valid KeyGesture.

Examples

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 CloseCmdKeyGesture = new KeyGesture(
    Key.L, ModifierKeys.Alt);

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

this.InputBindings.Add(CloseKeyBinding);
Dim CloseCmdKeyGesture As New KeyGesture(Key.L, ModifierKeys.Alt)

Dim CloseKeyBinding As New KeyBinding(ApplicationCommands.Close, CloseCmdKeyGesture)

Me.InputBindings.Add(CloseKeyBinding)

Remarks

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.

See also

Applies to

KeyGesture(Key, ModifierKeys, String)

Initializes a new instance of the KeyGesture class with the specified Key, ModifierKeys, and display string.

public:
 KeyGesture(System::Windows::Input::Key key, System::Windows::Input::ModifierKeys modifiers, System::String ^ displayString);
public KeyGesture (System.Windows.Input.Key key, System.Windows.Input.ModifierKeys modifiers, string displayString);
new System.Windows.Input.KeyGesture : System.Windows.Input.Key * System.Windows.Input.ModifierKeys * string -> System.Windows.Input.KeyGesture
Public Sub New (key As Key, modifiers As ModifierKeys, displayString As String)

Parameters

key
Key

The key associated with the gesture.

modifiers
ModifierKeys

The modifier keys associated with the gesture.

displayString
String

A string representation of the KeyGesture.

Exceptions

modifiers is not a valid ModifierKeys

-or-

key is not a valid Key.

displayString is null.

key and modifiers do not form a valid KeyGesture.

Remarks

The DisplayString property is set to the displayString parameter.

See also

Applies to