So what I ended up doing is customize the style in the XAML WPF code
<Window.Resources>
<Style TargetType="DataGridCell" x:Key="rightAlignCell">
<Setter Property="HorizontalAlignment" Value="Right"></Setter>
</Style>
</Window.Resources>
And then I set the cell style to this style in code.
Private Sub datagrid1_AutoGeneratingColumn(sender As System.Object, e As System.Windows.Controls.DataGridAutoGeneratingColumnEventArgs) Handles datagrid1.AutoGeneratingColumn
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)}"
End If
e.Column.CellStyle = TryCast(FindResource("rightAlignCell"), Style)
End If
end sub
source
share