共用方式為


KeyGesture 建構函式

定義

初始化 KeyGesture 類別的新執行個體。

多載

名稱 Description
KeyGesture(Key)

初始化一個新的類別實例 KeyGesture ,並指定為 Key

KeyGesture(Key, ModifierKeys)

初始化一個新的類別實例 KeyGesture ,並指定為 KeyModifierKeys和 。

KeyGesture(Key, ModifierKeys, String)

初始化一個新的類別實例 KeyGesture ,使用指定的 KeyModifierKeys、 和 顯示字串。

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

範例

以下範例說明如何使用此構造子建立 a KeyGesture 並將其與 KeyBindingKeyBinding接著 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)

備註

在大多數情況下,a KeyGesture 必須與一個或多個 ModifierKeys相關聯。 此規則的例外是功能鍵和數字鍵盤鍵,兩者本身都可以有效 KeyGesture

另請參閱

適用於

KeyGesture(Key, ModifierKeys)

初始化一個新的類別實例 KeyGesture ,並指定為 KeyModifierKeys和 。

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

範例

以下範例說明如何使用此構造子建立 a KeyGesture 並將其與 KeyBindingKeyBinding接著 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)

備註

在大多數情況下,a KeyGesture 必須與一個或多個 ModifierKeys相關聯。 此規則的例外是功能鍵和數字鍵盤鍵,兩者本身都可以有效 KeyGesture

另請參閱

適用於

KeyGesture(Key, ModifierKeys, String)

初始化一個新的類別實例 KeyGesture ,使用指定的 KeyModifierKeys、 和 顯示字串。

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

另請參閱

適用於