0

Im using DataGrid with columns:

<DataGrid.Columns>
   ...
   <DataGridTextColumn Header="my value" Binding="{Binding Path=MyValue, ValidatesOnDataErrors=True, StringFormat=0.000000}"/>
</DataGrid.Columns>

How can I use output format depending on users current culture?

For example 0,203 for german or 0.203 for us or something like this...

MikroDel
  • 6,705
  • 7
  • 39
  • 74
  • Your current code should already be culture specific. From [MSDN](https://msdn.microsoft.com/en-us/library/0c899ak8(v=vs.110).aspx#SpecifierPt): _The "." custom format specifier inserts a localized decimal separator into the result string_. If you would like to fix culture you could add `ConverterCulture=en-GB` for example – dkozl May 07 '15 at 10:42
  • @dkozl I have found the answer – MikroDel May 08 '15 at 08:21

2 Answers2

3

It is cause by default, WPF uses en-US as the culture, regardless of the system settings.

From two SO answers: first and second.

And this is the code to fix it:

FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.Name)));

In the answers above is CultureInfo.CurrentCulture.IetfLanguageTag recommended, but this is deprecated as for today and CultureInfo.CurrentCulture.Name should be used instead of it.

Community
  • 1
  • 1
MikroDel
  • 6,705
  • 7
  • 39
  • 74
0

For anyone finding this a few years later: while the accepted answer works, it affects the entire application and may have adverse effects. To limit the culture setting to the datagrid use

myDataGrid.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);
Doorman
  • 29
  • 3
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34896593) – Chris Catignani Aug 30 '23 at 14:01