Lina
Lina

Reputation: 451

Make the header column separator visible

I have used this xaml code to modify the background color of my DataGrid Header and the column separator visibility. My problem is that the column separators are elminated so the column headers look a little bit different:

this is my code :

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

How can I make the header column separtor visible?

Upvotes: 0

Views: 5449

Answers (1)

Marko Devcic
Marko Devcic

Reputation: 1101

Try this style

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

Hope it helps you, you can modify it further if you need it ...

Upvotes: 1

Related Questions