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

Overview

RadDataGrid provides an intuitive set of APIs that allow different aspects of its behavior to be handled and/or overridden. This can be done by adding commands through the Commands property, which gets a collection with all of the custom commands registered with the CommandService.

CommmandService

The RadDataGrid exposes a CommandService property which provides the following methods:

  • CanExecuteCommand(CommandId id, object parameter): Determines whether the command, associated with the specified Id can be executed given the parameter provided. If a custom command with the provided id is added to the Commands collection, it will be used instead of the default one.

  • CanExecuteDefaultCommand(CommandId id, object parameter): Determines whether the default command, associated with the specified Id can be executed given the parameter provided.

  • ExecuteCommand(CommandId id, object parameter): Attempts to find the command, associated with the specified Id and to perform its Execute routine, using the provided parameter. If a custom command with the provided id is added to the Commands collection, it will be used instead of the default one.

  • ExecuteDefaultCommand(CommandId id, object parameter): Executes the default (built-in) command (without looking for user-defined commands), associated with the specified Id.

Command Types

There are two types of commands:

  • DataGridCommand: All the default commands within RadDataGrid derive from the base DataGridCommand. Think of this command as a UI-related one as it operates over the RadDataGrid instance that owns the command.

Custom commands have a higher priority than the built-in (default) ones.

  • DataGridUserCommand: This specific command type provides an abstraction over the UI-related commands over a stateless and UI-agnostic generic command implementation. The command exposes the following properties:

    • Id: Gets or sets the CommandId member that this command is associated with.
    • Command: Gets or sets the generic ICommand implementation that may come from the ViewModel.
    • EnableDefaultCommand: Gets or sets a value indicating whether the default (built-in) UI command associated with the specified Id will be executed. Default value is True.

Example 1: Binding to a Command in the ViewModel

<Grid xmlns:grid="using:Telerik.UI.Xaml.Controls.Grid" 
      xmlns:gridCommands="using:Telerik.UI.Xaml.Controls.Grid.Commands"> 
    <grid:RadDataGrid Width="600" Height="460" x:Name="grid"> 
        <grid:RadDataGrid.Commands> 
            <gridCommands:DataGridUserCommand Id="CellTap" Command="{Binding MyCommand}"/> 
        </grid:RadDataGrid.Commands> 
    </grid:RadDataGrid> 
</Grid> 

CommandId Enumeration

All the predefined commands are identified by a member of the CommandId enumeration. This is actually the key that relates a command instance to a particular action/routine within the owning grid. In order to register a custom command you may either inherit the DataGridCommand class and override its CanExecute and Execute methods or instantiate a DataGridUserCommand instance and set its Command property. In both cases you need to set the Id property of the new command so that it can be properly associated with the desired action/event. Following are the members of the CommandId enumerations:

In this article
Not finding the help you need?