Tutorial :Validate control manually in WPF



Question:

Here is the situation: I have a dataset bound to a WPF window. The dataset implements the IDataErrorInfo, so when a value is changed in the window, a validation occurs for the specific property changed. During validation, I may find out there is another control in the window I need to validate. I know only the field name in the Dataset that I need to validate, and not the actual control that binds to this field. So my questions are: 1. How can I find out what control binds to a specific field in a Dataset? 2. How do I trigger validation on that control by code?

Thanks!


Solution:1

Two options as I see it:

  1. I think one way to handle this is in the setter for the property that's changed, clear the property that's no longer valid (if it is indeed not valid now).
  2. Another trick might be in the setter of the 1st property to raise a PropertyChanged event on the 2nd property, to force the view to reevaluate it.

I would prefer the 1st option, since you know changing the 1st property has a chance to invalidate the other property.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »