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 命令。 执行键手势时,将调用“打开”命令。

<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 实现能够以字符串的形式指定值。 此类型转换行为设置此属性的属性值形式。 还可以将 CommandCommandParameterCommandTarget 属性 ICommand 绑定到对象上定义的 。 这使你可以定义自定义命令并将其与用户输入相关联。 有关详细信息,请参阅 中的第二个 InputBinding示例。

XAML 属性用法

<inputBindingDerivedClassCommand=“ICommand”/>

XAML 属性元素用法

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

XAML 值

inputBindingDerivedClass
的派生类 InputBinding ,它支持对象元素语法,例如 KeyBindingMouseBinding。 请参阅“备注”。

iCommandImplementation
支持对象元素语法的 的对象 ICommand 实现 (具有公共无参数构造函数) 。

适用于

另请参阅