InputBinding Class

Represents a binding between an InputGesture and a command. The command is potentially a RoutedCommand.

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

public class InputBinding : DependencyObject, 
	ICommandSource
<inputBindingDerivedClass…/>

XAML Values

inputBindingDerivedClass

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

When the InputGesture associated with a InputBinding is performed, the ICommand associated with the InputBinding is executed.

An InputBinding can be defined on a specific object or at the class level by registering a RegisterClassInputBinding with the CommandManager.

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 set properties on the derived class that are inherited from InputBinding with a XAML usage. Two existing InputBinding derived classes that can be instantiated in XAML and can set properties in XAML are KeyBinding and MouseBinding. The typical property in WPF programming that is set in XAML and takes one or more InputBinding objects as values is the UIElement.InputBindings property.

The following example shows how to use a KeyBinding to bind a KeyGesture to the 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);

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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