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

屬性值

相關聯的命令。

屬性

例外狀況

範例

下列範例示範如何使用 KeyBinding 將 系結 KeyGestureApplicationCommands.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 使用方式設定屬性為 KeyBindingMouseBinding

ICommand 會參考類型轉換器,讓某些預先存在的 ICommand 實作以字串形式指定值。 這個類型轉換行為會設定這個屬性的屬性值格式。 您也可以將 CommandCommandParameter屬性 CommandTarget 系結到 ICommand 物件上定義的 。 這可讓您定義自定義命令,並將其與使用者輸入產生關聯。 如需詳細資訊,請參閱 中的第二個 InputBinding範例。

XAML Attribute Usage

<inputBindingDerivedClassCommand=“ICommand”/>

XAML 屬性項目用法

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

XAML 值

inputBindingDerivedClass
的衍生類別 InputBinding ,支援物件項目語法,例如 KeyBindingMouseBinding。 請參閱<備註>。

iCommandImplementation
的物件實作 ICommand ,支援對象專案語法 (具有公用無參數建構函式) 。

適用於

另請參閱