Monday, March 17, 2014

WPF DataGrid Custommization using Style and Template

Inline image 1

Introduction 
In this article we will go though how to change the appearance of the datagrid control.

how to customize template of DataGridColumnHeader, DataGridRow, DataGridCell, DatagridRowHeader and ScrollViewer of the DataGrid.

In this article you can learn, how to expand multiple RowDetailTemplate using  DatagridRowHeader style, 

how to change ScrollBar style in DataGrid.  

Background

DataGrid is a powerful control in WPF. it is used to render collection of data in customization grid.

...
...

<Style TargetType="{x:Type DataGridCell}">
   <Setter Property="Template">
<Setter.Value>
  <ControlTemplate TargetType="{x:Type DataGridCell}">
   <Border x:Name="border"
Background="Transparent"
BorderBrush="Transparent"
BorderThickness="1"
SnapsToDevicePixels="True">
      <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
   </Border>
  </ControlTemplate>
</Setter.Value>
   </Setter>
</Style>  

Read more: Codeproject