Home > OS >  How to bind a datagrid column with StringFormat as N2 with CultureInfo "en-In"?
How to bind a datagrid column with StringFormat as N2 with CultureInfo "en-In"?

Time:04-27

In my wpf datagrid there is a column whose text I want to show as a number but as per Indian format. If I do the below in xaml

Binding="{Binding Path=Amt, StringFormat=N2}"

I get the number format as per en-US but I want it as per en-In.

How can I do that in xaml?

CodePudding user response:

Set the Language property of the DataGrid to "en-IN":

<DataGrid ... Language="en-IN">
    <DataGrid.Columns>
        <DataGridTextColumn Binding="{Binding Path=Amt, StringFormat=N2}" />
    </DataGrid.Columns>
</DataGrid>

Or replace the DataGridTextColumn with a DataGridTemplateColumn if you have different formats for different columns:

<DataGridTemplateColumn>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Amt, StringFormat=N2}" Language="en-IN" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Amt, StringFormat=N2}" Language="en-IN" />
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
  • Related