0

Im making a receipt for a fast food . one column is for price which i try to set it's as currency in xaml like this

 <DataGridTextColumn Header="MenuPrice" x:Name="MenuPrice" 
                                        Binding="{Binding MenuPrice, StringFormat=C2}" Width="100" />

In other places i get euro sign but only in datagrids i get it as dollar . how can i change it to actually follow the users windows configuration ? like other places.

enter image description here

if you see at the buttom i have a label which is the result of total like this

total.toString("c2");

and i get the euro sign but not in datagrid

Saeed Asgari
  • 357
  • 2
  • 14
  • Use this: Binding="{Binding Path=PrezzoListino, ConverterCulture='it-IT', StringFormat='\{0:€ #,##0.00\}'}" in the DataGridTextColumn. Example is for Italian culture, Euro currency and "PrezzoListino" field to bind to. – Andrea Antonangeli Nov 03 '18 at 16:17

2 Answers2

2

Set the Language property of the DataGrid to your thread's current culture:

yourDataGrid.Language = System.Windows.Markup.XmlLanguage.GetLanguage(System.Threading.Thread.CurrentThread.CurrentCulture.IetfLanguageTag);

I am afraid you cannot do this in pure XAML.

mm8
  • 163,881
  • 10
  • 57
  • 88
1

I believe this is basically a duplicate of this question.

The chosen answer states:

I'm not sure if this has been fixed in .NET 4, but WPF has never picked up the current culture when rendering things like currency or dates.

It also gives a solution.

Community
  • 1
  • 1
JoshuaTheMiller
  • 2,582
  • 25
  • 27
  • @phi1010 also pointed out a [different question](http://stackoverflow.com/questions/991526/wpf-xaml-bindings-and-currentculture-display) that was very similar if you wanted to do further reading. – JoshuaTheMiller Dec 20 '16 at 00:08