InputBinding.Command 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定與這個輸入繫結相關聯的 ICommand。
public:
property System::Windows::Input::ICommand ^ Command { System::Windows::Input::ICommand ^ get(); void set(System::Windows::Input::ICommand ^ value); };
[System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
[System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
public System.Windows.Input.ICommand Command { get; [System.Security.SecurityCritical] set; }
[System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)]
[System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")]
public System.Windows.Input.ICommand Command { get; set; }
[<System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)>]
[<set: System.Security.SecurityCritical>]
member this.Command : System.Windows.Input.ICommand with get, set
[<System.Windows.Localizability(System.Windows.LocalizationCategory.NeverLocalize)>]
[<System.ComponentModel.TypeConverter("System.Windows.Input.CommandConverter, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")>]
member this.Command : System.Windows.Input.ICommand with get, set
Public Property Command As ICommand
屬性值
相關聯的命令。
- 屬性
例外狀況
Command 值為 null
。
範例
下列範例示範如何使用 KeyBinding 將 系結 KeyGesture 至 ApplicationCommands.Open 命令。 執行按鍵手勢時,會叫用 Open 命令。
<Window.InputBindings>
<KeyBinding Key="B"
Modifiers="Control"
Command="ApplicationCommands.Open" />
</Window.InputBindings>
KeyGesture OpenKeyGesture = new KeyGesture(
Key.B,
ModifierKeys.Control);
KeyBinding OpenCmdKeybinding = new KeyBinding(
ApplicationCommands.Open,
OpenKeyGesture);
this.InputBindings.Add(OpenCmdKeybinding);
Dim OpenKeyGesture As New KeyGesture(Key.B, ModifierKeys.Control)
Dim OpenCmdKeybinding As New KeyBinding(ApplicationCommands.Open, OpenKeyGesture)
Me.InputBindings.Add(OpenCmdKeybinding)
備註
類別 InputBinding 不支援 XAML 使用方式,因為它不會公開公用無參數建構函式, (它具有無參數建構函式,但受到保護) 。 不過,衍生類別可以公開公用建構函式,因此可以使用繼承自 InputBinding的屬性。 兩個可在 XAML 中具現化的現有 InputBinding 衍生類別,而且可以使用 XAML 使用方式設定屬性為 KeyBinding 和 MouseBinding。
ICommand 會參考類型轉換器,讓某些預先存在的 ICommand 實作以字串形式指定值。 這個類型轉換行為會設定這個屬性的屬性值格式。 您也可以將 Command、 CommandParameter屬性 CommandTarget 系結到 ICommand 物件上定義的 。 這可讓您定義自定義命令,並將其與使用者輸入產生關聯。 如需詳細資訊,請參閱 中的第二個 InputBinding範例。
XAML Attribute Usage
<inputBindingDerivedClass
Command
=“ICommand”/>
XAML 屬性項目用法
<inputBindingDerivedClass>
<inputBindingDerivedClass.Command>
<iCommandImplementation/>
</inputBindingDerivedClass.Command>
</inputBindingDerivedClass>
XAML 值
inputBindingDerivedClass
的衍生類別 InputBinding ,支援物件項目語法,例如 KeyBinding 或 MouseBinding。 請參閱<備註>。
iCommandImplementation
的物件實作 ICommand ,支援對象專案語法 (具有公用無參數建構函式) 。
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應