Reputation: 7264
I have a ComboBox which I cannot bind directly to (due to this bug), so I set it's SelectedItem from a Behavior I've written. Now, if the property bound to my behavior's SelectedValue (instead of the ComboBox's SelectedValue) is invalid (e.g. nothing is selected in the comboBox, when there should be), I want to notify the ComboBox to "go red", and display an errorcode. I know this is something the Binding system (if NotifyOnValidationError=true) handles automatically (it sets the bound control's state and ErrorCode).
My question is two-fold:
edit: I've found Validation static class, but it only has GetHasErrors and GetErrors, while I'd need set methods for these. Is it hopeless?
Upvotes: 0
Views: 1733
Reputation: 7264
Okay, after a full day of reading forum posts about half-hack solutions for SL3 exception style validations and horrible ideas with attached properties and subclassing combobox (oh, the pain!), I've managed to combine it to a semi-working solution. :)
The trick is: a control listens on EVERY dependency property for validation notification including FrameworkElement.Tag!
Now what we need is an object implementing IDataErrorInfo to bind to the comboBox's Tag.
Since in my scenario, I'm using a Behavior to set the comboBox manually, I already have a bound data on the behavior, so all I did was bound the behavior's SelectedValue to the comboBox's Tag, and watch the fireworks!
Upvotes: 1