ConditionRacer
ConditionRacer

Reputation: 4498

WPF ValidatesOnDataErrors=False not working

I have my own errorprovider and do not want to use any of the built in WPF stuff. I have a textbox that is bound to an integer, and I have ValidatesOnExceptions=False and ValidatesOnDataErrors=False. But when I enter a non integer in the textbox I get a red border. Is there something I'm missing?

Upvotes: 3

Views: 1057

Answers (1)

parapura rajkumar
parapura rajkumar

Reputation: 24403

You have several options

  1. You can change your data type to string so that the default converter doesn't throw an exception when converting your data.
  2. You can use a custom value converter that doesn't throw an exception when your try to coax a string into an integer

    class CustomConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return value.ToString();
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            int x = -1;
            Int32.TryParse(value.ToString(), out x);
            return x;
        }
    }
    
  3. You can change the UpdateSourceTrigger to explicit and have control over the precisely when databinding is updated.

  4. You can use expression blend to edit a local copy of TextBox template and remove all things related to binding validation errors

Upvotes: 2

Related Questions