'How to override exception message generated by IValueConverter
I would like to override message provided by the custom conversion class which inherits IValueConverter interface.
public class BoolConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
//string convertedValue = "";
bool initialValue = (bool)value;
if (initialValue == false)
{
return "0";
}
else if (initialValue == true)
{
return "1";
}
else return null;//{ return convertedValue; }
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
string initialValue = ((string)value).Trim();
try {
if (initialValue == "1") { return true; }
else if (initialValue == "0") { return false; }
else { return null; }
}
catch (Exception)
{
return null;
}
}
}
For example, if I enter 3 into text box binded with property I am receiving message: Value '3' could not be converted. I would like to provide longer message.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
