我試圖找出如何更改代碼的自動生成的列的文本對齊方式。如何更改Autogeneratedcolumn文本對齊
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
試着改變細胞的風格 – atomaras
@atomaras我不知道我會怎麼做,要改變對齊。任何代碼示例? – donL