wpf Datagrid 货币总是 $

wpf Datagrid currency is alway $

我正在开快餐收据。一栏是价格,我尝试将其设置为 xaml 中的货币 像这样

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

在其他地方我得到欧元符号,但只有在数据网格中我得到它作为美元。我如何更改它以实际遵循用户 windows 配置?像其他地方一样。

如果你在底部看到我有一个标签,它是这样的合计结果

total.toString("c2");

我得到了欧元符号,但数据网格中没有

我相信这基本上是 this question 的副本。

chosen answer 状态:

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.

也给出了解决方法

将 DataGrid 的语言 属性 设置为线程的当前文化:

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

恐怕你无法在纯 XAML 中做到这一点。