-2

I created Datagrid in my WPF project and binded ItemsSource with object that contains double type variable amount. I binded DataGridTextColumn with amount variable and used UpdateSourceTrigger to update it on any change by setting it to PropertyChanged (I really need this). Problem is, by typing for example 3,5, after source update value is changing to 35. When I'm typing 3.5, after update it stays as 3.5.

What I tried?

  • Changing CultureInfo in whole Thread and UIThread to InvariantCulture.
  • Checking my current OS region, by default it should use comma, not dot.

I have no idea, what problem is here. It's WPF project on .NET Framework 4.8. OS is Windows 10 and IDE is latest Visual Studio 2019.

GhostVolume
  • 81
  • 1
  • 7
  • Depending on UI culture, you work either with comma or dots. if UI thread set as for example EN then it will accepts dot, if you set as DE, then it will accepts comma. You might need a workaround or converter – Ugur Dec 02 '20 at 08:24
  • Does this answer your question? [How to make InvariantCulture recognize a comma as a decimal separator?](https://stackoverflow.com/questions/24375160/how-to-make-invariantculture-recognize-a-comma-as-a-decimal-separator) – Döharrrck Dec 02 '20 at 08:25
  • @Ugur `InvariantCulture` was wrong choice, I admit it. But using my local region culture, even if it uses comma, doesn't accept comma in my app. @Đøharrrck Only proved that using `InvariantCulture` was wrong. But using OS culture with comma is not making any change for app. – GhostVolume Dec 02 '20 at 08:40
  • @GhostVolume, but how do you use your local culture. You you should be changing your default culture, where your start your application. – Ugur Dec 02 '20 at 09:17
  • @GhostVolume: Try to set the `Language` property of the `DataGrid` to a culture that actually accepts a comma as the decimal separator: `` – mm8 Dec 02 '20 at 14:38
  • @mm8 Thank you, it helped. I wouldn't think there is `Language` property for `DataGrid`. I posted it as answer and mentioned you. I'm grateful. – GhostVolume Dec 03 '20 at 08:14
  • 1
    @GhostVolume: I posted an answer myself in case you want to accept it. – mm8 Dec 03 '20 at 14:22

1 Answers1

1

Try to set the Language property of the DataGrid to a culture that actually accepts a comma as the decimal separator, e.g.:

<DataGrid ...Language="sv-SE" />
mm8
  • 163,881
  • 10
  • 57
  • 88