New to Telerik UI for WPF? Download free 30-day trial

Keyboard Command Provider

RadVirtualGrid executes a certain set of commands for a given navigation scenario. This default consequences of commands can be altered by either implementing the IKeyboardCommandProvider interface or by inheriting the DefaultKeyboardCommandProvider object. The first approach would be quite laborious, as all commands will have to be predefined. When only a certain keyboard scenario needs to be modified, utilizing the DefaultKeyboardCommandProvider would be more appropriate.

The following code snippet illustrates a possible implementation of such custom KeyboardCommandProvider.

Example 1: Defining a custom KeyboardCommandProvider

public class CustomKeyboardCommandProvider: DefaultKeyboardCommandProvider 
{ 
    private RadVirtualGrid dataControl; 
 
    public CustomKeyboardCommandProvider(RadVirtualGrid dataControl) 
        :base(dataControl) 
    { 
        this.dataControl = dataControl; 
    } 
 
    public override IEnumerable<System.Windows.Input.ICommand> ProvideCommandsForKey(System.Windows.Input.Key key) 
    { 
        List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList(); 
 
        if (key == Key.Right) 
        { 
            commandsToExecute.Clear(); 
            commandsToExecute.Add(RadVirtualGridCommands.MoveNext); 
            commandsToExecute.Add(RadVirtualGridCommands.BeginEdit); 
        } 
 
        return commandsToExecute; 
    } 
} 

The final step is to apply the custom KeyboardCommandProvider to RadVirtualGrid through its KeyboardCommandProvider property.

Example 2: Applying the custom KeyboardCommandProvider

this.VirtualGrid.KeyboardCommandProvider = new CustomKeyboardCommandProvider(this.VirtualGrid); 

See Also

In this article