Click here to Skip to main content
15,882,055 members
Articles / Desktop Programming / XAML
Tip/Trick

DataGrid Visual Column Separator

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
6 Aug 2013CPOL 21.2K   7   3
DataGrid column separator

Introduction

I had to visually separate my DataGrid in two different parts. I used XAML to do so and added a small unused column. I searched for a solution but I didn't find anything that would solve my problem.

Using the Code

It is very simple, all in XAML. You just need to add a column and change the Header and Cell style.

XML
<DataGridTemplateColumn MinWidth="4" MaxWidth="4" 
IsReadOnly="True" CanUserResize="False">
    <DataGridTemplateColumn.HeaderStyle>
        <Style TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="Margin" Value="-1" />
            <Setter Property="Background" Value="Black" />
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="2" />
        </Style>
    </DataGridTemplateColumn.HeaderStyle>
    <DataGridTemplateColumn.CellStyle>
        <Style TargetType="{x:Type DataGridCell}">                       
            <Setter Property="BorderBrush" Value="Black" />
            <Setter Property="BorderThickness" Value="2" />                          
            <Setter Property="Focusable" Value="False" />
        </Style>
    </DataGridTemplateColumn.CellStyle>
</DataGridTemplateColumn> 

With this separator, you can't use arrow to go between the two parts of the DataGrid but with Tab it is alright.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Switzerland Switzerland
After graduating I started working as a Software Developer for a timing and scoring company.

Comments and Discussions

 
SuggestionPicture would be nice? Pin
Silvabolt31-Jul-13 9:02
Silvabolt31-Jul-13 9:02 
QuestionThis isn't ASP.NET... Pin
rbegley131-Jul-13 4:03
rbegley131-Jul-13 4:03 
AnswerRe: This isn't ASP.NET... Pin
Ced7435-Aug-13 22:39
professionalCed7435-Aug-13 22:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.