Skip to content

How can I control the width of DataGrid columns? #7612

Answered by luthfiampas
Gigas002 asked this question in Q&A
Discussion options

You must be logged in to vote

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.

<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>

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Gigas002
Comment options

@Gigas002
Comment options

Answer selected by Gigas002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants