How can I control the width of DataGrid columns? #7612
-
Here's the DataGrid I have: It's created this way on the <DataGrid AutoGenerateColumns="True" IsReadOnly="True" Items="{Binding Dependencies}"/> It seems, like the default value for |
Beta Was this translation helpful? Give feedback.
Answered by
luthfiampas
Feb 16, 2022
Replies: 1 comment 2 replies
-
You can use <DataGrid AutoGenerateColumns="False" Items="{Binding Users}">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="*" Binding="{Binding Name}" />
<DataGridTextColumn Header="Email" Width="3*" Binding="{Binding Email}" />
</DataGrid.Columns>
</DataGrid> To align column header text to center, add this to your style. <Style Selector="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment" Value="Center" />
</Style> |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Gigas002
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use
ColumnWidth
property. But if you want to control the width of individual column, you will need to define all the columns manually.To align column header text to center, add this to your style.