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

XAML 属性用法

< inputBindingDerivedClass Command=“”ICommand/>

XAML 属性元素用法

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

XAML 值

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

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

适用于

另请参阅