2

NOTE: this question is 8 years old! the WPF strategy for handing custom errors has significantly changed since it was asked. please see https://docs.microsoft.com/en-us/dotnet/framework/wpf/data/how-to-implement-binding-validation

I have a custom numeric text box bound to a double. on error, the default error message that shows (as a tooltip) is "can not convert string to double" or something similar.

How can I change that custom message?

I'm trying to do it through the converter:

class MyConverter : IValueConverter
  {

      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
          return 1234.23;
      }

      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
      {
           // if( value is not good)
           // ?? throw exception ?? 
      }
}
4

2 回答 2

2

Have a look at the validation Mechanisms in wpf.Its exactly what you are looking for

于 2011-06-06T17:45:24.113 回答
-1

You should be able to throw your own errors within the converter, and if you have the ValidateOnDataErrors=true then your validation template will display the exceptions error message. I believe,I haven't done this in a while!

于 2011-06-06T20:18:48.517 回答