Share via


KeyGesture 构造函数

定义

初始化 KeyGesture 类的新实例。

重载

KeyGesture(Key)

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

KeyGesture(Key, ModifierKeys)

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

KeyGesture(Key, ModifierKeys, String)

使用指定的 KeyGestureKey 和显示字符串初始化 ModifierKeys 类的新实例。

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 并将其与 KeyBinding关联。 KeyBinding然后将 添加到 InputBindingCollection 的 。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

keymodifiers 没有形成有效的 KeyGesture

示例

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

使用指定的 KeyGestureKey 和显示字符串初始化 ModifierKeys 类的新实例。

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

keymodifiers 没有形成有效的 KeyGesture

注解

属性 DisplayString 设置为 displayString 参数。

另请参阅

适用于