[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Collapse]MVVM Framework
  [Expand]View Models
  [Expand]Commands
  [Collapse]Behaviors
    Getting Started
   [Collapse]Predefined Set
     EventToCommand
     KeyToCommand
     FocusBehavior
     ValidationErrorsHostBehavior
     ConfirmationBehavior
     DependencyPropertyBehavior
     EnumItemsSourceBehavior
     CompositeCommandBehavior
     FunctionBindingBehavior
     MethodToCommandBehavior
     CurrentWindowSerializationBehavior
     BarSubItemThemeSelectorBehavior
     BarSplitItemThemeSelectorBehavior
     RibbonGalleryThemeSelectorBehavior
     RibbonGalleryItemThemePaletteSelectorBehavior
     ReadOnlyDependencyPropertyBindingBehavior
    How to: Create a Custom Behavior
  [Expand]Services
  [Expand]DXBinding
  [Expand]MIF
   Converters
   ViewLocator
   Messenger
   Data Annotation Attributes
   LayoutTreeHelper
   Weak Event
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

KeyToCommand

The KeyToCommand class is a special behavior that allows you to bind a KeyGesture to a command.

Expanded Getting Started with KeyToCommand

Assume that there is a requirement to handle a the key gesture of a control. For example, you need to invoke the ViewModel's CommitCommand when the end-user presses the Enter key while the focus is in the TextBox.

To accomplish this task, you can use the KeyToCommand behavior. Attach the KeyToCommand behavior to the TextBox's dxmvvm:Interaction.Behaviors collection.

Specify the key gesture that should be handled in the KeyToCommand.KeyGesture property and bind the EventToCommandBase.Command property to the CommitCommand.

Note that KeyToCommand uses the KeyUp event to handle KeyGestures by default. If necessary, you can specify any other event here, for example, KeyDown.

Due to the fact that the KeyToCommand and EventToCommand are inherited from one base class, their overall capabilities are similar to ProcessEventsFromDisabledEventOwner, MarkRoutedEventsAsHandled, UseDispatcher and DispatcherPriority.

Is this topic helpful?​​​​​​​