Is there any way to format the values that are bound to a datagrid? For example I have the following:
Use the StringFormat
property:
<DataGridTextColumn Binding="{Binding Path=Date, StringFormat=d}" Header="Date" />
<DataGridTextColumn Binding="{Binding Path=Amount, StringFormat=C}" Header="Amount" />
One easiest way. here in the code below use your language code as a value of ConverterCulture. you can find your language code here
<DataGridTextColumn Binding="{Binding Profit, ConverterCulture='gu-IN' ,StringFormat=c}" Header="Profit" Width="*" MinWidth="80" FontWeight="Normal"/>
the output will be in your local currency
for anything other than currency find stringFormat specifier here
If the stringformat is variable, the above solutions will not work.
<DataGrid.Resources>
<DataTemplate x:Key="YTemplate">
<Label Content="{Binding Y, Mode=OneWay}" ContentStringFormat="{Binding StringFormat, ElementName=Parent_UC}"/>
</DataTemplate>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Y" Width="*" CellTemplate="{StaticResource YTemplate}"/>
</DataGrid.Columns>