KeyGesture 建構函式

定義

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

多載

KeyGesture(Key)

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

KeyGesture(Key, ModifierKeys)

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

KeyGesture(Key, ModifierKeys, String)

使用指定的 KeyGesture, Key 和顯示字串初始化 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 加入 InputBindingCollectionWindow

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

與筆勢相關聯的輔助按鍵 (Modifier Key)。

例外狀況

modifiers 不是有效的 ModifierKeys

-或-

key 不是有效的 Key

keymodifiers 不會組成有效的 KeyGesture

範例

下列範例示範如何使用這個建構函式來建立 KeyGesture ,並將其與 KeyBinding產生關聯。 接著,會將 KeyBinding 加入 InputBindingCollectionWindow

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)

使用指定的 KeyGesture, Key 和顯示字串初始化 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

與筆勢相關聯的輔助按鍵 (Modifier Key)。

displayString
String

KeyGesture 的字串表示。

例外狀況

modifiers 不是有效的 ModifierKeys

-或-

key 不是有效的 Key

displayStringnull

keymodifiers 不會組成有效的 KeyGesture

備註

屬性 DisplayString 會設定為 displayString 參數。

另請參閱

適用於