How can I align the column data to center in a WPF DataGrid
?
Here's @MohammedAFadil's XAML answer, converted to C# code behind:
var MyStyle = new Style(typeof(DataGridCell)) {
Setters = {
new Setter(TextBlock.TextAlignmentProperty, TextAlignment.Center)
}
};
To apply the Style
, set the CellStyle
property of the DataGrid
, e.g.
var MyGrid = new DataGrid() {
CellStyle = MyStyle
};