New to Telerik UI for .NET MAUI? Start a free 30-day trial
Executing a Custom Command on DataGrid Column Header Tap in UI for .NET MAUI
Updated on Feb 17, 2026
Environment
| Version | Product | Author |
|---|---|---|
| 13.0.0 | Telerik UI for .NET MAUI DataGrid | Dobrinka Yordanova |
Description
I need to execute a custom command when a column header in the DataGrid is clicked. Is there a tapped command or similar functionality to bind custom logic to the header's click event?
This knowledge base article also answers the following questions:
- How to override the default sorting behavior of DataGrid headers?
- How to bind custom logic to DataGrid column header tap in UI for .NET MAUI?
- How to add a custom command to the DataGrid component?
Solution
To execute custom logic when a DataGrid column header is clicked, use the ColumnHeaderTap command. By default, this command sorts the column, but you can override the behavior.
- Define the DataGrid with columns in XAML:
xaml
<telerik:RadDataGrid ItemsSource="{Binding Items}" x:Name="grid" AutoGenerateColumns="False">
<telerik:RadDataGrid.Columns>
<telerik:DataGridTextColumn HeaderText="Name" PropertyName="Name" />
<telerik:DataGridNumericalColumn HeaderText="Age" PropertyName="Age" />
<telerik:DataGridTextColumn HeaderText="Email" PropertyName="Email" />
</telerik:RadDataGrid.Columns>
<telerik:RaddataGrid.BindingContext>
<local:MainViewModel />
</telerik:RaddataGrid.BindingContext>
</telerik:RadDataGrid>
- Create a
ViewModelwith sample data:
csharp
public class MainViewModel
{
public ObservableCollection<Person> Items { get; } = new()
{
new Person { Name = "Alice", Age = 30, Email = "" },
new Person { Name = "Bob", Age = 25, Email = "" },
new Person { Name = "Charlie", Age = 35, Email = "" }
};
}
public class Person
{
public string Name { get; set; } = string.Empty;
public int Age { get; set; }
public string Email { get; set; } = string.Empty;
}
- Implement a custom
ColumnHeaderTapCommandby inheriting from theDataGridCommandclass.
csharp
public class ColumnHeaderTapCommand : DataGridCommand
{
public ColumnHeaderTapCommand()
{
Id = DataGridCommandId.ColumnHeaderTap;
}
public override bool CanExecute(object parameter)
{
return true;
}
public override void Execute(object parameter)
{
if (parameter is Telerik.Maui.Controls.DataGrid.DataGridTextColumn)
{
// Add your custom logic here
}
}
}
- Add the custom command to the DataGrid's
Commandscollection.
csharp
this.grid.Commands.Add(new ColumnHeaderTapCommand());