Sebastian Busek
Sebastian Busek

Reputation: 1032

How to customize DataGrid header?

How can I customize DataGrid Header? This picture shows what I want to do... screenshot

I try this, but it not working...

<DataGridTemplateColumn.Header>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Text="Název modelu"></TextBlock>
        <TextBlock Grid.Column="0" Grid.Row="1" Text="Cena bez DPH"></TextBlock>
        <TextBlock Grid.Column="1" Grid.Row="1" Text="Cena s DPH"></TextBlock>
    </Grid>
</DataGridTemplateColumn.Header>

Can you help me, how can I do it?

Upvotes: 1

Views: 487

Answers (2)

nemesv
nemesv

Reputation: 139748

Try to set the HorizontalAlignment to Center on your TextBlock

<TextBlock HorizontalAlignment="Center" 
           Grid.Column="1" Grid.Row="1" Text="Cena s DPH"></TextBlock>

You can start here to read more about the WPF Layout system

You also need to set the HorizontalContentAlignment to for the DataGridColumnHeader

Add this to the DataGridTemplateColumn:

<DataGridTemplateColumn.HeaderStyle>
    <Style TargetType="DataGridColumnHeader">
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
</DataGridTemplateColumn.HeaderStyle>

Upvotes: 1

paparazzo
paparazzo

Reputation: 45096

Try Width="*" on the ColumnDefinitions

Upvotes: 0

Related Questions