wpf idataerrorinfo combobox
I have a simple view and viewmodel with the latter implementing IDdataErrorInfo and IValidationExceptionHandler. The view contains a combobox with its ItemsSource bound to an collection with SelectedValue bound to a property - validating on data errors and exceptions; updates on property changed and notifies on source updated.
I'm using data annotations and the property is "decorated" with Required as well as a Range attribute and I would upon executing the view have expected the combobox to display the error adorner and the message I've provided for the Required attribute. However, hovering over the adorner I notice the message is instead "Value "" could not be converted".
Do I have to check the selected value in the getter for the property and return a ValidationResult with my message if I find that no value has been selected? I thought just using the Required attribute would have done the trick but that doesn't seem to work for combob开发者_如何学运维oxes?
Any help much appreciated.
This usually happes if there is no representing item in the combobox for the default value of what type the SelectedValue represents.
Assuming that your bound selected value property is string there should be an item (in the ItemsSource) which represents the default value of string.empty.
And hence (probably) the error is Value "" could not be converted
Let me know if this helps.
精彩评论