1

I have a project where I'm databinding a gridview to a list, where one column is databound to a gridview. The problem I have is that with the double being 5.5 on one computer it appears as 5.5 in the gridview. But on another it looks like 55, the decimal mark dissapears. So 3.14 will look like 314 etc.

The error occurs with the following code:

myDatagrid.ItemsSource = someList;
Binding binding = new Binding("DoubleValue");
myColumnInDatagrid.Binding = binding;

I've also tried using a very simple valueconverter, that just return the double, and parsed it in ConvertBack. I'm pretty new to WPF so I'm sorry if I've made some obvious mistakes, I just don't understand why it works on one computer but not on the other. Perhaps it should be noted that both of the computers use the same operating system, with the same language settings (afaik at least).

H.B.
  • 166,899
  • 29
  • 327
  • 400
user1277327
  • 411
  • 1
  • 4
  • 9

2 Answers2

1

You could force the Binding object to use a specific CultureInfo object to handle the conversion, regardless of the current culture, by setting its ConverterCulture property explicitly as follows:

  binding.ConverterCulture=Globalization.CultureInfo.NeutralCulture

(reference: http://msdn.microsoft.com/en-us/library/system.windows.data.binding.converterculture.aspx)

Andrea Scarcella
  • 3,233
  • 2
  • 22
  • 26
0

FKE is right: Most probably the Culture differs on both computers hence the different display.

You can set the Culture via the binding or via FrameworkElement.Language and here's a nice way to set that globally for your whole application:

How to set current CultureUI via XAML binding

Community
  • 1
  • 1
SvenG
  • 5,155
  • 2
  • 27
  • 36