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
Hi Michael,
Thank you for reaching out us.
DataGridTextColumn does not support applying common column properties such as HeaderTextAlignment, HeaderPadding, CellTextAlignment, and CellPadding through a shared Style targeting the column type.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:
Best Regards,
Muthupandy R.
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
Thank you for your patience.
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.
Best Regards,
Muthupandy R.
- 3 Replies
- 2 Participants
-
MI Michael
- Aug 2, 2026 02:54 PM UTC
- Aug 4, 2026 02:16 PM UTC