2012-12-03 97 views
0

我正在使用Xceed数据网格控件,并试图更改标题颜色,但似乎遇到了一些麻烦。我现在所拥有的是下面的代码片段:在WPF中使用Xceed Datagrid更改网格标题的颜色

Style style = new Style(typeof(ColumnManagerRow)); 
style.Setters.Add(new Setter(ColumnManagerRow.BackgroundProperty, Brushes.Black)); 
this.grid.Resources[typeof(ColumnManagerRow)] = style; 

这适用于大多数情况,但我仍然看到周围的一些灰色。任何帮助将不胜感激。

编辑

我用,我想有作为相同颜色的选定区域添加图像。 enter image description here

回答

1

你可以在XAML做到这一点:

<ControlTemplate x:Key="HeaderTemplate" TargetType="{x:Type xcdg:ColumnManagerCell}"> 
    <TextBlock Text="{TemplateBinding Content}"> 
     <TextBlock.Style> 
      <Style TargetType="{x:Type TextBlock}"> 
       <Setter Property="Background" Value="Black" /> 
       <Setter Property="Foreground" Value="Red" /> 
      </Style> 
     </TextBlock.Style> 
    </TextBlock> 
</ControlTemplate> 

<Style TargetType="{x:Type xcdg:ColumnManagerRow}"> 
    <Setter Property="Background" Value="Black"/> 
    <Setter Property="BorderBrush" Value="Black"/> 
</Style>     

<Style TargetType="{x:Type xcdg:ColumnManagerCell}"> 
    <Setter Property="Template" Value="{StaticResource HeaderTemplate}"/> 
</Style> 
+0

这是不是给我同样的结果吗? – Seb

+0

是的,我发布了错误的风格。我编辑了答案,样式目标应该是'xcdg:ColumnManagerCell'。 – dzavala

+0

我仍然看到单元格周围的灰色边框。它看起来比以前更薄。 – Seb

相关问题