InputBinding.Command Property

Gets or sets the ICommand associated with this input binding.

Namespace:  System.Windows.Input
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

'Declaration
<TypeConverterAttribute("System.Windows.Input.CommandConverter, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, Custom=null")> _
<LocalizabilityAttribute(LocalizationCategory.NeverLocalize)> _
Public Property Command As ICommand
'Usage
Dim instance As InputBinding 
Dim value As ICommand 

value = instance.Command

instance.Command = value
<inputBindingDerivedClass>
  <inputBindingDerivedClass.Command>
    <iCommandImplementation/>
  </inputBindingDerivedClass.Command>
</inputBindingDerivedClass>
<inputBindingDerivedClass Command="ICommand"/>

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 default constructor).

Property Value

Type: System.Windows.Input.ICommand
The associated command.

Implements

ICommandSource.Command

ExceptionCondition
ArgumentNullException

The Command value is Nothing.

The InputBinding class itself does not support XAML usage, because it does not expose a public default constructor (there is a default constructor, but it is protected). However, derived classes can expose a public constructor and thus 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.

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft