KeyGesture 類別

定義

定義可以用來叫用 (Invoke) 命令的鍵盤組合。

public ref class KeyGesture : System::Windows::Input::InputGesture
[System.ComponentModel.TypeConverter(typeof(System.Windows.Input.KeyGestureConverter))]
public class KeyGesture : System.Windows.Input.InputGesture
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Input.KeyGestureConverter))>]
type KeyGesture = class
    inherit InputGesture
Public Class KeyGesture
Inherits InputGesture
繼承
KeyGesture
屬性

範例

下列範例示範如何使用 將命令系結 CloseKeyGestureKeyBinding

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)

下列範例示範如何在 XAML 中使用 KeyGesture 。 請注意,XAML 使用方式不會直接宣告 <KeyGesture> 專案。 無法使用該物件專案,因為 KeyGesture 不會公開公用無參數建構函式。 相反地,XAML 用法會使用 typeconverter 行為,將整個 KeyGesture 內嵌宣告為 Gesture 屬性值。

<Window.InputBindings>
  <KeyBinding Command="ApplicationCommands.Open"
              Gesture="CTRL+R" />
</Window.InputBindings>

備註

在大部分情況下, KeyGesture 必須與一或多個 ModifierKeys相關聯。 此規則的例外狀況是函式索引鍵和數位按鍵,其本身可以是有效的 KeyGesture 。 例如,您可以只使用 F12 金鑰來建立 KeyGesture ,但若要在中使用 KeyGesture X 鍵,則必須與修飾詞索引鍵配對。

您可以使用 KeyBinding 系結 KeyGestureICommand,以便在發生 時 KeyGesture 叫用命令。

針對 KeyGesture XAML 使用方式,通常會在 XAML 中設定的屬性是 Gesture,在手勢同時代表標準索引鍵和修飾詞索引鍵的情況下。 您也可以將 Gesture 屬性設定為只是函式索引鍵,或只是修飾詞按鍵組合。 不過,如果預期的命令系結是沒有修飾詞的函式索引鍵,或是Modifiers預期的命令系結僅供修飾詞索引鍵使用,則Key設定 屬性會比較常見。

XAML Attribute Usage

<object property="oneOrMoreModifierKeys+key"/>  
- or -  
<object property="functionKey"/>  

XAML 值

functionKey
Key

單一索引鍵值,必須是 F1-12) 或數值按鍵鍵 (其中一個函式索引鍵。

oneOrMoreModifierKeys
列舉所 ModifierKeys 定義的一或多個修飾詞索引鍵,並以 “+” 字元分隔。

key
Key

單一索引鍵值。

建構函式

KeyGesture(Key)

使用指定的 KeyGesture 初始化 Key 類別的新執行個體。

KeyGesture(Key, ModifierKeys)

使用指定的 KeyGestureKey,初始化 ModifierKeys 類別的新執行個體。

KeyGesture(Key, ModifierKeys, String)

使用指定的 KeyGesture, Key 和顯示字串初始化 ModifierKeys 類別的新執行個體。

屬性

DisplayString

取得這個 KeyGesture 的字串表示。

Key

取得與這個 KeyGesture 關聯的按鍵。

Modifiers

取得與這個 KeyGesture 關聯的輔助按鍵。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetDisplayStringForCulture(CultureInfo)

傳回可用來顯示 KeyGesture 的字串。

GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
Matches(Object, InputEventArgs)

判斷這個 KeyGesture 是否符合與指定 InputEventArgs 物件關聯的輸入。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱