Tendrás que personalizarlo. De esta manera:
class YesNoConverter : BooleanConverter {
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType) {
if (value is bool && destinationType == typeof(string)) {
return values[(bool)value ? 1 : 0];
}
return base.ConvertTo(context, culture, value, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) {
string txt = value as string;
if (values[0] == txt) return false;
if (values[1] == txt) return true;
return base.ConvertFrom(context, culture, value);
}
private string[] values = new string[] { "No", "Yes" };
}
Ejemplo de uso:
class MyControl : Control {
[TypeConverter(typeof(YesNoConverter))]
public bool Prop { get; set; }
}
No se obtiene ninguna ayuda de System.Globalization para hacer este trabajo en otros idiomas.
Gracias, cierre, pero cuando hago doble clic en el valor obtengo un Error Dlg "El valor de la propiedad no es válido"/"Objeto del tipo 'System.String' no se puede convertir a tipo 'System.Boolean'." –
Ugh, pita. Coloque un PropertyGrid en un formulario para depurar esto en tiempo de ejecución. –
Es posible que necesite System :: Convert :: ToBoolean (value) en lugar del molde para bool. – ThePragmatist