KeyToCommand Class

Allows you to bind a KeyGesture to a command.

Namespace: DevExpress.Mvvm.UI

Assembly: DevExpress.Xpf.Core.v21.1.dll

Declaration

public class KeyToCommand :
    EventToCommandBase

Remarks

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

Getting Started with KeyToCommand

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

[POCOViewModel]
public class MainViewModel {
    ...
    public void Commit() {
        ...
    }
}

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

<TextBox>
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:KeyToCommand />
    </dxmvvm:Interaction.Behaviors>
</TextBox>

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

<TextBox>
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:KeyToCommand KeyGesture="Enter" Command="{Binding CommitCommand}"/>
    </dxmvvm:Interaction.Behaviors>
</TextBox>

Note that KeyToCommand uses the KeyUp event to handle KeyGestures (the default behavior). 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, and DispatcherPriority.

Inheritance

Show 13 items
Object
DispatcherObject
DependencyObject
Freezable
Animatable
DevExpress.Mvvm.UI.Interactivity.AttachableObjectBase
DevExpress.Mvvm.UI.Interactivity.Behavior
DevExpress.Mvvm.UI.Interactivity.TriggerBase
DevExpress.Mvvm.UI.Interactivity.TriggerBase<DependencyObject>
EventTriggerBase<DependencyObject>
DevExpress.Mvvm.UI.Interactivity.EventTrigger
EventToCommandBase
KeyToCommand
See Also