I would like to display warnings and errors when validating a business object and have these displayed visually to the user.
For example I have a business object class implementing an interface like so:
interface IOrderItem : IDataErrorInfo
{
int ProductId { get; set; }
string ProductName { get; set; }
decimal Price { get; set; }
IDictionary<string, string> Warnings { get; }
}
This is bound to the UI as follows:
<TextBox Text="{Binding Price, ValidatesOnDataErrors=True}/>
An error would be:
This works nicely and draws a red border around the textbox when I put the error message on the business object using the IDataErrorInfo
interface.
What I would like to do is also specify warnings, for example:
These warnings would put an orange border around a text box and inform the user that there may be a problem but not stop them proceeding.
The warnings are stored in a string dictionary mapping PropertyName => WarningMessage in a similar way to IDataErrorInfo
.
Question: What is the best way to go about this?
Have you checked this http://www.codeproject.com/KB/WPF/wpfvalidation.aspx
EDIT: Please find the sample here http://www.filefactory.com/file/b3b4cb7/n/ValidationErrorsSample.zip
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With