The Command design-pattern is very important and widely used in the XAML and MVVM world. RadDataGrid strictly follows these best practices and provides an intuitive and easy-to-use set of APIs that allow different aspects of the RadDataGrid control’s behavior to be handled and/or completely overridden.

RadDataGrid exposes a Commands collection that allows you to register custom commands with each control’s instance through the RadDataGrid.Commands property:

  • Commands: Gets the collection with all the custom commands registered with the CommandService. Custom commands have higher priority than the built-in (default) ones.

Command Types

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

    • Id: The key that relates a command instance to a particular action/routine. This value is used to associate a command with a known event within a RadDataGrid instance.
    • 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.

DataGridCommandId Enumeration

All the predefined commands within a RadDataGrid instance are identified by a member of the DataGridCommandId 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 within a RadDataGrid instance you may either inherit the DataGridCommand class and override its CanExecute and Execute methods. 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 DataGridCommandId enumerations:

The table below shows all commands in the RadDataGrid control and for each of the available commands there is an object which is passed as a parameter in its Execute method.

Commands Object type
Unknown DataGridColumn
ColumnHeaderTap DataGridTextColumn
GroupHeaderTap GroupHeaderContext
GroupHeaderButtonTap GroupHeaderContext
CellTap DataGridCellInfo
CellDoubleTap DataGridCellInfo
GenerateColumn GenerateColumnContext
DataBindingComplete DataBindingCompleteEventArgs
BeginEdit EditContext
CancelEdit EditContext
CommitEdit EditContext
ValidateCell ValidateCellContext
LoadMoreData CommandsViewModel


Here is the definition of the DataGrid control:

<grid:RadDataGrid x:Name="grid" ItemsSource="{Binding}"/>

In the example the following business object is used:

public class Country
    public Country(string name, double population)
        this.Name = name;
        this.Population = population;

    public string Name { get; set; }
    public double Population { get; set; }

Here is the simple data used as binding context:

var source = new ObservableCollection<Country>();
source.Add(new Country("Mozambique", 24692000));
source.Add(new Country("Paraguay", 6725000));
source.Add(new Country("Turkmenistan", 5663000));
source.Add(new Country("Mongolia", 3027000));
source.Add(new Country("Japan", 127000000));
source.Add(new Country("Bulgaria", 7128000));
source.Add(new Country("Chad", 14450000));
source.Add(new Country("Netherlands", 17020000));

this.BindingContext = source;

Let;s handle the CellTap action as a Command. First, create a class that inherits from the DataGridCommand and set its Id property accordingly. You would also need to override CanExecute and Execute methods as demostrated in the example below:

public CellTapUserCommand()
    Id = DataGridCommandId.CellTap;
public override bool CanExecute(object parameter)
    return true;
public override void Execute(object parameter)
    var context = parameter as DataGridCellInfo;
    var cellTap =  $"CellTap Command on cell {context.Value} inside {context.Column.HeaderText} \n";
    //add your logic here
    Application.Current.MainPage.DisplayAlert("", "You've selected " + cellTap, "OK");

Then add this Command to the Commands collection of the RadDataGrid instance:

grid.Commands.Add(new CellTapUserCommand());

SDK Samples Browser application contains an example that shows how to use the CellTap Command.

See Also

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article