通过


KeyGesture 构造函数

定义

初始化 KeyGesture 类的新实例。

重载

名称 说明
KeyGesture(Key)

用指定的KeyGesture值初始化类的新实例Key

KeyGesture(Key, ModifierKeys)

使用指定的KeyGestureKey. 初始化类的新实例ModifierKeys

KeyGesture(Key, ModifierKeys, String)

使用指定的 KeyModifierKeys显示字符串初始化类的新实例KeyGesture

KeyGesture(Key)

用指定的KeyGesture值初始化类的新实例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)

参数

key
Key

与此手势关联的键。

例外

key 不是有效的 Key

key 不是有效的 KeyGesture

示例

以下示例演示如何使用此构造函数创建 KeyGesture 并将其与 a KeyBinding. 然后,将 KeyBinding 它添加到 InputBindingCollection 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)

注解

在大多数情况下, KeyGesture 必须与一个或多个 ModifierKeys关联。 此规则的例外情况是函数键和数字键盘键,它们本身可能有效 KeyGesture

另请参阅

适用于

KeyGesture(Key, ModifierKeys)

使用指定的KeyGestureKey. 初始化类的新实例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)

参数

key
Key

与手势关联的键。

modifiers
ModifierKeys

与手势关联的修饰键。

例外

modifiers 无效 ModifierKeys

-或-

key 不是有效的 Key

key 并且 modifiers 不构成有效的 KeyGesture

示例

以下示例演示如何使用此构造函数创建 KeyGesture 并将其与 a KeyBinding. 然后,将 KeyBinding 它添加到 InputBindingCollection 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)

注解

在大多数情况下, KeyGesture 必须与一个或多个 ModifierKeys关联。 此规则的例外情况是函数键和数字键盘键,它们本身可能有效 KeyGesture

另请参阅

适用于

KeyGesture(Key, ModifierKeys, String)

使用指定的 KeyModifierKeys显示字符串初始化类的新实例KeyGesture

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)

参数

key
Key

与手势关联的键。

modifiers
ModifierKeys

与手势关联的修饰键。

displayString
String

KeyGesture字符串表示形式。

例外

modifiers 无效 ModifierKeys

-或-

key 不是有效的 Key

displayStringnull

key 并且 modifiers 不构成有效的 KeyGesture

注解

DisplayString 属性设置为 displayString 参数。

另请参阅

适用于