简体   繁体   中英

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?

此页面描述了 WPF 的一个错误(功能?),除非您采取措施以其他方式指定以及如何修复它,否则文化将始终为美国。

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM