New to Telerik UI for .NET MAUI? Start a free 30-day trial
Specifying the CellContentTemplate Binding in a MAUI DataGrid with a DataTable
Updated on Sep 24, 2025
Environment
| Version | Product | Author |
|---|---|---|
| 6.7.0 | Telerik UI for .NET MAUI DataGrid | Dobrinka Yordanova |
Description
When using a CellContentTemplate with a RadDataGrid that uses a DataTable as a source, you need to specify the binding for the template. This article provides an example of how to do this.
Solution
To specify the binding for a CellContentTemplate follow these steps:
- Define the
RadDataGridand set itsItemsSourceproperty to the data source. - Create the necessary columns and specify the
PropertyNamefor each column. - Inside the
CellContentTemplateof the desired column, define the desired control and bind it to the appropriate property using the indexer syntax—[PropertyName].
Here is an example of a RadDataGrid with two columns and binding in the template in XAML and C#:
xaml
<telerik:RadDataGrid ItemsSource="{Binding Data}" AutoGenerateColumns="False">
<telerik:RadDataGrid.BindingContext>
<local:DataTableViewModel/>
</telerik:RadDataGrid.BindingContext>
<telerik:RadDataGrid.Columns>
<telerik:DataGridTextColumn PropertyName="City">
<telerik:DataGridTextColumn.CellContentTemplate>
<DataTemplate>
<Label Text="{Binding [City]}"/>
</DataTemplate>
</telerik:DataGridTextColumn.CellContentTemplate>
</telerik:DataGridTextColumn>
<telerik:DataGridBooleanColumn PropertyName="IsVisited">
<telerik:DataGridBooleanColumn.CellContentTemplate>
<DataTemplate>
<telerik:RadCheckBox IsChecked="{Binding [IsVisited]}"/>
</DataTemplate>
</telerik:DataGridBooleanColumn.CellContentTemplate>
</telerik:DataGridBooleanColumn>
</telerik:RadDataGrid.Columns>
</telerik:RadDataGrid>Make sure to add the PropertyName to each column to specify the binding. In this example, the City column is a DataGridTextColumn, and the IsVisited column is a DataGridBooleanColumn.
Create a ViewModel class to provide the data source for the RadDataGrid. Here is an example of the ViewModel:
csharp
public class DataTableViewModel : NotifyPropertyChangedBase
{
private DataTable data;
public DataTableViewModel()
{
this.Data = this.GetData();
}
public DataTable Data
{
get { return this.data; }
set { this.UpdateValue(ref this.data, value); }
}
private DataTable GetData()
{
DataTable country = new DataTable();
country.TableName = "Cities";
country.Columns.Add("Id", typeof(int));
country.Columns.Add("City", typeof(string));
country.Columns.Add("Population", typeof(int));
country.Columns.Add("Visited On", typeof(DateTime));
country.Columns.Add("IsVisited", typeof(bool));
country.Rows.Add(0, "Sofia", 2000000, new DateTime(2012, 10, 1), true);
country.Rows.Add(1, "New York", 8419000, null, false);
country.Rows.Add(2, "London", 8982000, new DateTime(2019, 02, 11), true);
country.Rows.Add(3, "Los Angeles", 3967000, null, false);
country.Rows.Add(4, "Budapest", 1765000, new DateTime(2013, 02, 1), true);
country.Rows.Add(5, "Tokyo", 9375104, new DateTime(2015, 09, 1), true);
return country;
}
}
Notes
- The indexer syntax
[PropertyName]is used to bind to a specific property in theDataRowView. - Make sure to set the
PropertyNamefor each column to specify the binding.