I am trying to figure out how to change the text alignment of an auto generated column in code.
Private Sub dgBook_AutoGeneratingColumn(sender As System.Object, e As System.Windows.Controls.DataGridAutoGeneratingColumnEventArgs) Handles dgBook.AutoGeneratingColumn
If e.PropertyType = GetType(DateTime) Then
Dim dataGridTextColumn As DataGridTextColumn = TryCast(e.Column, DataGridTextColumn)
If dataGridTextColumn IsNot Nothing Then
dataGridTextColumn.Binding.StringFormat = "{0:d}"
End If
End If
If e.PropertyName = "Amount" Then
Dim dataGridTextColumn As DataGridTextColumn = TryCast(e.Column, DataGridTextColumn)
If dataGridTextColumn IsNot Nothing Then
dataGridTextColumn.Binding.StringFormat = "{0:#,##0.00;(#,##0.00)}"
'I tried the next line for testing but it did not work
dataGridTextColumn.SetValue(TextBox.TextAlignmentProperty, TextAlignment.Center)
End If
End If
End Sub