KeyBinding.Gesture 属性

定义

获取或设置与此 KeyBinding 关联的笔势。Gets or sets the gesture associated with this KeyBinding.

public:
 virtual property System::Windows::Input::InputGesture ^ Gesture { System::Windows::Input::InputGesture ^ get(); void set(System::Windows::Input::InputGesture ^ value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.Input.KeyGestureConverter))]
public override System.Windows.Input.InputGesture Gesture { get; set; }
member this.Gesture : System.Windows.Input.InputGesture with get, set
Public Overrides Property Gesture As InputGesture

属性值

键序列。The key sequence. 默认值是 nullThe default value is null.

属性

例外

gesture 将要设置为的值不是 KeyGesturethe value gesture is being set to is not a KeyGesture.

示例

下面的示例演示如何使用 KeyBindingKeyGesture 绑定到 RoutedCommand (标记和代码示例指定不同的键,但在其他方面等效)。The following example shows how to bind a KeyGesture to a RoutedCommand using a KeyBinding (the markup and code examples specify different keys but are otherwise equivalent).

<Window.InputBindings>
  <KeyBinding Command="ApplicationCommands.Open"
              Gesture="CTRL+R" />
</Window.InputBindings>
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 必须包含 Key 和一个或多个 ModifierKeysWith the exception of the function keys and the numeric keypad keys, a KeyGesture must contain a Key and one or more ModifierKeys.

适用于

另请参阅