Crystal
Crystal

Reputation: 29458

Datagrid, first column to be left-justified, the rest be centered

I have a DataGrid, that references another style that sets the property for the ColumnHeaderStyle to be centered.

<Style x:Key="CenterDataGridStyle" TargetType="{x:Type DataGrid}">
                <Style.Setters>                    
                    <Setter Property="ColumnHeaderStyle" Value="{StaticResource CenterColumnHeaderStyle}"/>                    
                </Style.Setters>
            </Style>

Is there a way in the code behind to make the DataGrid have its first column to be left-justified instead of center? I got so far as:

dtGridReads.Columns[0].

then I'm not sure if there was a property I could set for this or not? Thanks.

Upvotes: 0

Views: 83

Answers (1)

CodingGorilla
CodingGorilla

Reputation: 19842

There is not a single property like HorizontalAlignment that you can set on the column, instead you'll need to construct a Style similar to what you have in XAML, and apply it to the column.

Upvotes: 1

Related Questions