WPF converters: where does the culture come from

二次信任 提交于 2019-12-08 17:12:03

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/801789/wpf-converters-where-does-the-culture-come-from

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!