DataGrid eats the comma

Apr 30, 2009 at 10:29 AM
I am trying to implement a column in which the balance of a transaction is shown. I am using a TemplateCellColumn which contains a TextBox for editing the cell.
Now when the user enters a value like this 25,50 (In Germany we are using , as seperator for Euro and Cent) the , simply disapears and the value 2550 is set. When I type in 25.50 everything works like expexted. I have another Textbox in my UI when I set the value 25,50 in this Box everything goes the right way. Both Textboxes use the same Converters (ConvertBack simply returns the value entered), the only difference is that the first one is in the Grid and the other one not.

Can anybody help me please?
Apr 30, 2009 at 12:45 PM
There was a discussion here not too long ago about a very similar issue, and as I recall then it had something to do with the CurrentCulture or CurrentUICulture turning out to be wrong when the converter got called and that there was some XAML property that could be set to fix that. You may want to check that the culture passed to the converter is what you expect, and failing that, a forum search on those terms might be a good start.

Hope this helps.
Apr 30, 2009 at 12:55 PM
Hi!
Do you mean this Thread:
http://wpf.codeplex.com/Thread/View.aspx?ThreadId=51692 ?

JanR is writing that he can use a converter that completely ignores the UICulture and returns the correct value. In my converter I am not using the UICulture too. 
The ConvertBack Method is very simple:
return value;
I debuged my application and it returns the correct value 25,50 but when my setter on the object is called (directly after the Converter) the comma is gobne and 2550 is set...
Apr 30, 2009 at 3:15 PM
Yes, without having read it over in detail again, that looks like it's the one I was thinking about. The question would be what exactly is "eating" the comma, because I really doubt the TextBox or even the DataGrid would be doing it. (I've been working with WPF for some time now and never seen anything like that.) I would probably look very closely at what the converter gets (it should get exactly the value you entered) and what it returns. It might also be worthwhile to double-check all data types involved. Just the fact that the US number format works and the German one breaks still makes me inclined to think that this is a culture-dependent issue, however.

Normally, it is the Convert method that gets called on an IValueConverter, not ConvertBack, so the fact that ConvertBack does exactly what it is supposed to do when it simply returns the value that was passed to it says very little. Actually, a lot of IValueConverter examples I've seen simply throw NotImplementedException in ConvertBack.
May 4, 2009 at 1:41 PM
It has been the ConvertBack method, because it get's called when the user sets a value that is bound to the UIelement with Mode=TwoWay.
The Convert-method was working fine.
I did a lot of logging in this Converter and noticed that it is not enough to simply return the value is not enough. I found a very simple fix (At least for the moment, it needs further testing). Now I am replacing , with .

So it is no DataGrid-Bug ;-)
Thank you for your help mikj.