語言

InputBinding.Command 屬性

定義

取得或設定與此輸入綁定相關的 。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

屬性值

相關指揮部。

屬性

例外狀況

範例

以下範例展示了如何使用 a KeyBinding 將 a 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的屬性。 兩個現有 InputBinding 的衍生類別可在 XAML 中實例化,並能設定 XAML 使用法的屬性,分別是 KeyBinding 和 MouseBinding。

ICommand 參考一種型別轉換器,使某些既有 ICommand 實作能以字串形式指定值。 這種型別轉換行為會設定此屬性的屬性值形式。 你也可以將 、 Command和 CommandParameter 屬性綁定CommandTarget到定義在物件上的 。ICommand 這讓你能定義自訂指令,並將其與使用者輸入關聯。 更多資訊請參見 。InputBinding

XAML 屬性使用方式

< inputBindingDerivedClass Command=“ICommand”/>

XAML 屬性元素使用方式

<inputBindingDerivedClass>
  <inputBindingDerivedClass.Command>
    <iCommandImplementation/>
  </inputBindingDerivedClass.Command>
</inputBindingDerivedClass>

XAML 值

inputBindingDerivedClass 一個支援物件元素語法的衍生類別 InputBinding ,例如 KeyBinding 或 MouseBinding。 請參閱備註。

iCommandImplementation 一個支援物件元素語法的物件實作 ICommand (擁有公開的無參數建構器)。

適用於

另請參閱