Articles in this section
Category / Section

How to apply padding for column elements in .NET MAUI DataGrid?

2 mins read

The .NET MAUI DataGrid allows you to configure the padding values for each cell, enabling enhanced layout customization. The CellPadding and HeaderPadding properties can be used to set padding for both data cells and header cells, respectively.

XAML
You can update the padding of each cell using the following XAML code. The CellPadding property targets the DataGridCell, while HeaderPadding targets the DataGridHeaderCell.

<syncfusion:SfDataGrid x:Name="dataGrid"
                    x:DataType="local:EmployeeViewModel"
                    RowHeight="30"
                    ColumnWidthMode="Auto"
                    ItemsSource="{Binding Employees}">
    <syncfusion:SfDataGrid.Columns>
        <syncfusion:DataGridNumericColumn MappingName="EmployeeID" HeaderText="Employee ID" Format="D" CellPadding="0" HeaderPadding="0"/>
        <syncfusion:DataGridTextColumn MappingName="Name" CellPadding="16, 0 ,16, 0" HeaderPadding="16 ,0, 16, 0" />
        <syncfusion:DataGridTextColumn MappingName="Title" CellPadding="16, 0, 16, 0" HeaderPadding="16, 0, 16, 0"/>
    </syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>

C#
Similar code to XAML

DataGridNumericColumn EmployeeIDColumn = new DataGridNumericColumn() { MappingName = "EmployeeID" , HeaderText = "Employee ID" , Format= "D" , CellPadding  = new Thickness(16,0,16,0), HeaderPadding = new Thickness(16,0,16,0) };

DataGridTextColumn NameColumn = new DataGridTextColumn() { MappingName = "Name", HeaderText = "Name",  CellPadding = new Thickness(16, 0, 16, 0), HeaderPadding = new Thickness(16, 0, 16, 0) };

DataGridTextColumn Title = new DataGridTextColumn() { MappingName = "Title", HeaderText = "Title", CellPadding = new Thickness(16, 0, 16, 0), HeaderPadding = new Thickness(16, 0, 16, 0) };

dataGrid.Columns.Add(EmployeeIDColumn);
dataGrid.Columns.Add(NameColumn);
dataGrid.Columns.Add(Title);

Output

SfDataGrid_ColumnPadding.png

Download the complete sample from GitHub.

Conclusion

I hope you enjoyed learning how to apply padding for Column Elements in .NET MAUI DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied