Technisches‎ > ‎

How to localize boolean for usage in Propertygrid


[TypeConverter(typeof(BooleanconverterDE))]
Public bool ExampleProperty{ get; set; }


class BooleanconverterDE : BooleanConverter

{

    private readonly string trueString = "Ja";

    private readonly string falseString = "Nein";

    public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)

    {

        if (value != null && value is string)

        {

            if ((string)value == trueString) return true;

            if ((string)value == falseString) return false;

        }

        return base.ConvertFrom(context, culture, value);

    }

    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)

    {

        if (destinationType == typeof(string) && value != null && value is bool)

        {

            if ((bool)value == true) return trueString;

            if ((bool)value == false) return falseString;

        }

        return base.ConvertTo(context, culture, value, destinationType);

    }

}


Source: http://www.pcreview.co.uk/forums/thread-3448745.php

Comments