Edit

Share via


InputBinding.Command Property

Definition

Gets or sets the ICommand associated with this input binding.

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

Property Value

The associated command.

Attributes

Exceptions

The Command value is null.

Examples

The following example shows how to use a KeyBinding to bind a KeyGesture to the ApplicationCommands.Open command. When the key gesture is performed, the Open command is invoked.

<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)

Remarks

The InputBinding class does not support XAML usage because it does not expose a public parameterless constructor (it has a parameterless constructor, but it is protected). However, derived classes can expose a public constructor and therefore, can use properties that are inherited from InputBinding. Two existing InputBinding derived classes that can be instantiated in XAML and can set properties with XAML usages are KeyBinding and MouseBinding.

ICommand references a type converter that enables certain preexisting ICommand implementations to specify values in the form of a string. This type conversion behavior sets the attribute value form of this property. You can also bind the Command, CommandParameter, and CommandTarget properties to an ICommand that is defined on an object. This enables you to define a custom command and associate it with user input. For more information, see the second example in InputBinding.

XAML Attribute Usage

<inputBindingDerivedClass Command="ICommand"/>

XAML Property Element Usage

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

XAML Values

inputBindingDerivedClass
A derived class of InputBinding that supports object element syntax, such as KeyBinding or MouseBinding. See Remarks.

iCommandImplementation
An object implementation of ICommand that supports object element syntax (has a public parameterless constructor).

Applies to

See also