Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF converters: where does the culture come from

I've created a WPF converter class:

public class DoubleConverter : IValueConverter
{
    public object Convert(object value, Type TargetType, object parameter, CultureInfo culture)
    {
        //blah blah
    }
}

I wonder who sets the culture parameter that is passed. I would expect it to be the same as the current windows settings, but it appears to be different.

Anyone?

like image 409
Robbert Dam Avatar asked Apr 29 '09 10:04

Robbert Dam


2 Answers

This page describes a bug (feature?) of WPF where culture will always be en-US unless you take action to specify otherwise and how to fix it.

like image 140
Martin Harris Avatar answered Oct 13 '22 01:10

Martin Harris


Actually, using the technique described on that page is a bad idea -- it doesn't take into account any customisations that the user has made to their formatting settings in the Control Panel.

Instead, just ignore the culture parameter passed in to the converter entirely; if you need to pass a culture on to something else, use CultureInfo.CurrentCulture. (Since this is the default for Parse and ToString, you usually don't need to pass it on anyway.)

like image 30
Miral Avatar answered Oct 12 '22 23:10

Miral