I'm trying to do some simple TextBox validation and found the ExceptionValidationRule class. My XAML is (basically)
and the MyText property is (basically)Code:<TextBox> <TextBox.Text> <Binding Path="MyText" UpdateSourceTrigger="PropertyChanged"> <Binding.ValidationRules> <ExceptionValidationRule /> </Binding.ValidationRules> </Binding> </TextBox.Text> </TextBox>
When run in debug mode, if I edit the text so that it becomes invalid, instead of just outlining the TextBox in red like I want, a debug window comes up saying the "Not valid." application exception was unhandled. When run outside of debug mode, it works properly.Code:public string MyText { get { return this.myText; } set { this.myText = value; if (!MyTextIsValid(value)) throw new ApplicationException("Not valid."); else OnPropertyChanged("MyText"); } }
I ran someone else's example code, though it wasn't written for VS2010. After running the upgrade wizard and the application, the same error appears. I also found a forum post which seems to describe my issue precisely, though it had no replies.
Since I've never used data validation before, I wanted to make sure I wasn't doing anything wrong and that this is indeed a bug. So, anybody have confirmation it's a bug or advice on what I'm doing wrong?
P.S. I'm aware there should be workarounds with the more complex validation techniques. I don't want to use them on principle, particularly since the non-debug version works fine.


Reply With Quote