Assembly: PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
A associates a KeyGesture with a ICommand, such as a RoutedCommand. RoutedCommand is the primary implementation of the ICommand interface for the WPF commanding system . In general, when the KeyGesture is executed the command is invoked, although the command behavior is further influenced by command-specific factors such as the CanExecute value. For more information on commanding, see the Commanding Overview.
With the exception of the function keys and the numeric keypad keys, a valid KeyGesture must contain exactly one Key and one or more ModifierKeys. Function keys and numeric keypad keys do not require a modifier key in order to be a valid KeyGesture. It is possible to specify an invalid KeyGesture and a with an invalid associated gesture, either through XAML or code. For instance, there is no validation that prevents creating and binding a KeyGesture that contains only a nonfunction key, or only modifiers but no key. Such a will never attempt to invoke its associated command.
When defining a in Extensible Application Markup Language (XAML) there are two ways to specify the KeyGesture. The first way to establish a in XAML is to define the Gesture attribute of the element, which enables a syntax to specify keys and modifiers as a single string, for example "CTRL+P". The second way is to define the Key attribute and the Modifiers attributes of the element. Both ways of setting the KeyGesture are equivalent and modify the same underlying object, but there will be a conflict if both are used. In the case when the Key, Modifiers, and the Gesture attributes are all set, the attribute which is defined last will be used for the KeyGesture. You can potentially have situations where for example a Key set last will overwrite just the Key component of a preceding Gesture but leave the Gesture's modifiers the same. In general, it is recommended that you use only the Gesture attribute from XAML; this will avoid ambiguity, provides the most streamlined syntax, and provides the most straightforward representation for serialization.
A can be defined on a specific object or at the class level by registering a RegisterClassInputBinding on the CommandManager class. The most typical way to define a is within the control template, setting the InputBindings property in XAML by declaring one or more MouseBinding or elements.
The following example creates a and adds it to the InputBindingCollection of the root window.
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.