Cell Alignment In DataGrid In WPF


In this article we will see how we can change the Cell Alignment in DataGrid in WPF.

Crating WPF Application Project

Fire up Visual Studio 2008 and Create a WPF Application and name the project as CellAlignmentDataGridWPF.

Let’s have a DataGrid and then we would bind some sample data to it, so that we can visualize the Data in DataGrid.

The above class represents the structure of Employee Entity.

Now we would have some sample data and bind it to DataGrid.

Now we will run the application and see how the cell alignement are look by default.

As you see in above display the default alignement of the DataGrid Cell is Left Alignment.

Now we would try to have Right and Center Alignement for Cells too.

We have to create a style that would Change the Template of DataGridCell, so let’s do it.

The above styles are for DataGridCell. Now we will use Custom columns in our DataGrid and have these styles applied on.

Now let’s see how does it look in run time.

As simple as that. So we have achieved the Cell Alignment in DataGrid.

Hope this article helps.

Related Posts:

1) Making Timeline Control for DataGrid In WPF

2) Custom Gridline Color of Datagrid In WPF

3) Custom Row and Header Height of Datagrid In WPF

4) Rounded Corner Datagrid In WPF

5) Tooltip In DataGrid In WPF

6) Grouping In Datagrid In WPF

7) Edit Row Details In Context Menu In DataGrid In WPF

8) Hide/Un-Hide Columns Using Context Menu In DataGrid In WPF

9) Hide &Un-Hide DataGrid Column(s) In WPF

10) ComboBox In DataGrid In WPF

11) DatePicker In DataGrid In WPF

12) CRUD Operation In DataGrid In WPF