metacircle
metacircle

Reputation: 2578

Datagrid Column Header Templating

I want to template some headercolumns in a pretty simple way, but I don't get the results I am looking for. I want the Border to fill the whole header, not just the textbox inside. Right now I am still having the default gray behind my own controls.

<DataGrid x:Name="grdItems"
    Grid.Row="0"
    CanUserAddRows="False"
    CanUserDeleteRows="False"
    ItemsSource="{Binding Path=Items}"
    CanUserSortColumns="False" AutoGenerateColumns="False" CanUserResizeColumns="False">
<DataGrid.Columns>
<DataGridComboBoxColumn ItemsSource="{Binding Source={StaticResource GetSignalTypeValues}}" Width="auto" SelectedValueBinding="{Binding SignalType}" >
    <DataGridComboBoxColumn.HeaderTemplate>
        <DataTemplate>
            <Border Background="Orange" >
                <TextBlock Text="Signal Type" />
            </Border>
        </DataTemplate>
    </DataGridComboBoxColumn.HeaderTemplate>
</DataGridComboBoxColumn>

<DataGridTextColumn Width="auto" Binding="{Binding AmplitudeMax}">
    <DataGridTextColumn.HeaderTemplate>
        <DataTemplate>
            <Border Background="Violet">
                <StackPanel>
                    <TextBlock Text="Amplitude" HorizontalAlignment="Center" />
                    <TextBlock Text="-maximum-" HorizontalAlignment="Center" />
                </StackPanel>
            </Border>
        </DataTemplate>
    </DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>

Upvotes: 0

Views: 2641

Answers (1)

Rafal
Rafal

Reputation: 12619

If you are only after background color of column header you can utilize this:

<DataGridComboBoxColumn  Width="auto" SelectedValueBinding="{Binding SignalType}" >
    <DataGridComboBoxColumn.HeaderStyle>
        <Style TargetType="DataGridColumnHeader">
            <Setter Property="Background" Value="Orange"/>
        </Style>
    </DataGridComboBoxColumn.HeaderStyle>

Upvotes: 2

Related Questions