我已使用此xaml代码修改DataGrid标头的背景颜色和列分隔符可见性。我的问题是列分隔符已被删除,因此列标题看起来有点不同:
这是我的代码:
<DataGrid AutoGenerateColumns="False" Grid.ColumnSpan="9" Grid.Row="1" Height="82" HorizontalAlignment="Left" Margin="99,427,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="363" Background="#9DB9EB" >
<DataGrid.Columns>
<DataGridTextColumn Header="Header1" />
<DataGridTextColumn Header="Header2" />
</DataGrid.Columns>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="Background" Value="#cee8ef" />
<Setter Property="BorderThickness" Value="2" />
</Style>
</DataGrid.ColumnHeaderStyle>
</DataGrid>
如何使标题列separtor可见?
答案 0 :(得分:1)
试试这种风格
<Style TargetType="{x:Type DataGridColumnHeader}"
>
<Setter Property="Background"
Value="#cee8ef" />
<Setter Property="BorderThickness"
Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label
Content="{TemplateBinding Content}"
Grid.Column="0"
HorizontalAlignment="Center"
Margin="10,0,25,0" />
<Thumb HorizontalAlignment="Right"
Grid.Column="1"
Name="PART_HeaderGripper"
Margin="0,4,0,4"
Width="2"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
希望对您有所帮助,如果您需要,可以进一步修改......