This post provides an example of how you can right-align or centre the text in a DataGridRowHeader in a DataGrid in WPF using Visual Studio 2012 or later. It also explains how you can display the correct row numbers in the DataGridRowHeader and automatically update these as you are adding or removing items to and from the DataGrid’s ItemsSource collection dynamically.
The DataGrid control has a RowHeaderTemplate property that defines the DataTemplate for the DataGridRowHeader. A DataGridRowHeader is by default displayed to the left of the left-most data column on each row in the DataGrid. It doesn’t scroll horizontally with the rest of the columns and is usually used to display some additional information that associated with a specific row, for example a row number.
The RowHeaderTemplate DataTemplate doesn’t inherit the data context from the DataGridRow but since it gets added to the visual tree, you can use a…
View original post 777 more words