Datagrid列标题模板

时间:2012-07-26 10:21:24

标签: wpf datagrid

我想以一种非常简单的方式模拟一些headercolumns,但我没有得到我正在寻找的结果。我希望边框填充整个标题,而不仅仅是文本框内部。现在我仍然在我自己的控件后面有默认的灰色。

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

1 个答案:

答案 0 :(得分:2)

如果你只是在列标题的背景颜色之后,你可以利用它:

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