views:

82

answers:

2

Essentially the warning in our case is just a validation, we don't want to mark it as an error just a warning so the user knows. I was hoping to use the same or similar method used for validation. Currently I'm leaning towards implementing IDataErrorInfo. But I'd like to change the style on display and allow saving. Has anyone done anything similar? I don't want 2 separate solutions for validation.

+1  A: 

WPF has a built-in mechanism for handling validation via IDataErrorInfo.

There is a good CodeProject article describing the process, but it basically comes down to supplying an ErrorTemplate that's used for items in an error state, and telling WPF to validate your objects. If they implement IDataError info, you can have their style change, plus use that to present error messages directly.

Reed Copsey
Yes I know this. I didn't ask my question well. There is no way for WPF to differentiate an error from a warning, ie An error should me marked in red, a warning in yellow.
nportelli
+1  A: 

during validation, set some corresponding properties. eg: IsInWarning and IsInError.

set these properties according to the validation logic in the error handler and then use a datatemplate to style the items with triggers.

something like that?

(sorry no time to mock up an example now...)

Roel
Yes actually. I was going to do that with the warnings and let IDataError take care of the errors. I'm going to give it a go and see how it turns out.
nportelli

related questions