views:

37

answers:

2

I'm building a SL4 app. Currently, my validation works for the following scenario:

  • User focuses on the text box
  • User types invalid data
  • User loses focus on the text box

However, it does not work for this:

  • User focuses on the text box, which already contains invalid data
  • User loses focus on the text box

How can I get validation to trigger in that second case?

The reason I'm doing it is that I have a "Name" field that is initially empty but must be populated. If the user skips over it, I'd like to flag the error.

A: 

Starting with your name case: There's a built in [Required] validator you can use. Whether this will do the trick depends on how you've implemented your input form.

If it doesn't trigger in the scenario you describe you can write a method to be called on Submit, LostFocus or wherever it suits the solution, that browses the Visual Tree that contains your form and trigger the validations.

ChristianL
Indeed, looks like the `[Required]` validator you pointed me towards will solve this issue as well. I'm currently struggling to get a `DataForm` into my SL4 project.
Rosarch
A: 

Validation occurs as soon as new data are transmitted from the UI to the view model. In default this happens on the lost focus, but you can change this default, to either each time input is changed(a ner key is hit) or manual (bycalling a method of the binding class).

In any case it is very confusing for the user to see invalid data when the form appears....pls avoid it. Do a manual Validatio before showing the form....and then try to correct or cancel invalid data before showing it.

Francesco Abbruzzese