[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
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Collapse]MVVM Framework
  [Expand]View Models
    Getting Started
   [Collapse]Predefined Set
    How to: Create a Custom Behavior
   Data Annotation Attributes
   Weak Event
 [Expand]Controls and Libraries
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)


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?​​​​​​​