Assign same properties to multiple columns

Hello,

I have a Grid with multiple Text Columns (DataGridTextColumn) and I want to set the properties HeaderTextAlignment, HeaderPadding, CellTextAlignment and CellPadding for each column to the same values.

Is there a way to create a style and assign it to all columns instead of repeating those properties for each columnm?

Example:

<syncGrid:DataGridTextColumn HeaderText="Duration"
                             HeaderTextAlignment="Center" 
                             HeaderPadding="8,6" 
                             CellTextAlignment="Center" 
                             CellPadding="8,6"
                             MappingName="P1Duration"
                             Width="{OnIdiom Phone=75, Default=85}" />
<syncGrid:DataGridTextColumn HeaderText="Points"
                             HeaderTextAlignment="Center" 
                             HeaderPadding="8,6" 
                             CellTextAlignment="Center" 
                             CellPadding="8,6"
                             MappingName="P1Points"
                             Width="{OnIdiom Phone=170, Default=220}" />
<syncGrid:DataGridTextColumn HeaderText="Score"
                             HeaderTextAlignment="Center" 
                             HeaderPadding="8,6" 
                             CellTextAlignment="Center" 
                             CellPadding="8,6"
                             MappingName="P1Score"
                             Width="{OnIdiom Phone=65, Default=80}" />


I tried defining a style in the resources section of the page:

<Style TargetType="syncGrid:DataGridTextColumn">
    <Setter Property="HeaderTextAlignment" Value="Center" />
    <Setter Property="HeaderPadding" Value="8,6" />
    <Setter Property="CellTextAlignment" Value="Center" />
    <Setter Property="CellPadding" Value="8,6" />
</Style>

But that didn't work. Any suggestions?


Thanks for your help.

Regards,

Michael







3 Replies

MR Muthupandy Ramakrishnan Syncfusion Team August 3, 2026 07:33 AM UTC

Hi Michael,
Thank you for reaching out us.
Currently, the DataGridTextColumn does not support applying common column properties such as HeaderTextAlignment, HeaderPadding, CellTextAlignment, and CellPadding through a shared Style targeting the column type.
As a workaround, you can create reusable styles for DataGridHeaderCell and DataGridCell, and assign them to the HeaderStyle and CellStyle properties of each column. This approach enables you to centralize alignment and padding settings while reducing repetitive code.


Example:

<ContentPage.Resources>
<Style TargetType="syncfusion:DataGridHeaderCell"
x:Key="customHeaderStyle">
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Padding" Value="8,6" />
</Style>
<Style TargetType="syncfusion:DataGridCell"
x:Key="customCellStyle">
<Setter Property="TextAlignment" Value="Center" />
<Setter Property="Padding" Value="8,6" />
</Style>
</ContentPage.Resources>

<syncfusion:SfDataGrid x:Name="dataGrid"
AutoGenerateColumnsMode="None"
ItemsSource="{Binding OrdersInfo}">
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridTextColumn MappingName="OrderID"
HeaderText="Order ID"
Width="150"
CellStyle="{StaticResource customCellStyle}"
HeaderStyle="{StaticResource customHeaderStyle}" />

<syncfusion:DataGridTextColumn MappingName="FirstName"
HeaderText="First Name"
Width="150"
CellStyle="{StaticResource customCellStyle}"
HeaderStyle="{StaticResource customHeaderStyle}" />

<syncfusion:DataGridTextColumn MappingName="EmployeeID"
HeaderText="Employee ID"
Width="150"
CellStyle="{StaticResource customCellStyle}"
HeaderStyle="{StaticResource customHeaderStyle}" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
Using this approach, you only need to define the alignment and padding settings once and can reuse them across all columns, making your code easier to maintain and update.
Please let us know if you have any further questions. We will be happy to assist you.



Best Regards,
Muthupandy R.



MI Michael August 3, 2026 08:29 AM UTC

Hello,


Thank you! That helps at least a bit


I encountered a problem with the <style> approach. I want to set the background of a specific column to a predefined color. But DynamicResources don't work here:


 <Style x:Key="SeparatorCellStyle" TargetType="syncGrid:DataGridCell" >
     <Setter Property="Background" Value="{DynamicResource PrimaryBackgroundColor}" />
 </Style>


In contrast, if I change it to a fixed color it works.

<Style x:Key="SeparatorCellStyle" TargetType="syncGrid:DataGridCell" >
    <Setter Property="Background" Value="Red" />
</Style>


<syncGrid:DataGridTextColumn HeaderText="" MappingName="Separator" 
                             CellStyle="{StaticResource SeparatorCellStyle}"
                             Width="5" />


Am I doing something wrong?


Regards

MIchael



MR Muthupandy Ramakrishnan Syncfusion Team August 4, 2026 02:16 PM UTC

Hi Michael,
Thank you for your patience.
We have checked your query at our end, and we are able to replicate that issue at our end where the Background property set through a DynamicResource in the DataGridCell style is not applied correctly, while assigning a fixed color value works as expected. We have considered this as a bug and logged a bug report regarding this in our feedback portal. We will fix the reported issue and include the changes in our upcoming weekly patch release, which is expected to be rolled out on August 25, 2026. We will let you know once released, and we appreciate your patience until then. You can also track the status of the bug using the feedback link below.


Disclaimer: Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.

We appreciate your patience and understanding. Please let us know if you have any further questions or need additional assistance. We will be happy to help.


Best Regards,
Muthupandy R.


Loader.
Up arrow icon