Silverlight 3 validation using Prism

I am developing an SL3 application with Prism. I need to maintain validation (both field level (in the bound property setter) and before save (form level)), including the validation summary shown when the save button is clicked.

But the samples I can find on google are SL3 with a lot of code in code (very miraculous and unprincipled) or WPF related.

Does anyone know of a referenced app with some actual validation that I can look at?

Cheers, Ali

+1


a source to share


1 answer


Currently there are none from Microsoft, but I will submit this to the PRISM team tomorrow to see if we can get a basic example of form validation in the next rev of PRISM.

That being said, you can put a validator on a form that essentially validates every field (semantic and / or syntactic validation) and must pass everything, return a true / false state.

As usual I do this, I attach the "CanSave" method to my commands, that is:

SaveOrderCommand = new DelegateCommand<object>(this.Save, this.CanSave);

private bool CanSave(object arg)
{
     return this.errors.Count == 0 && this.Quantity > 0;
}

      

Then in this.CanSave I will then put either a basic validation inside that codebase or I will call a bunch of other validators depending on the context - some of them will be shared across all modules (i.e. IsEmailValid will be the same Validator I am in my infrastructure module as a singleton and pass in my string, then it will be true / false in the result). Once they all pass, make sure CanSave returns true. If they don't work, CanSave will return False.



Now if they fail and you want to trigger a friendly reminder to the user that it failed to create a number of methods you can use here. I used to mark the specified control as "failed" on validation. (I've written my own take on you, so it's up to you what tools you can use here - http://www.codeplex.com/SilverlightValidator is pretty good).

Now I usually like to do more with Forms that have validation on them, not only highlighting the specified control (red box, icon, etc.), but also explaining to the user in more detail which of them is required - thus a custom approach is the solution I have chosen.

At the end of the day, you will have to do some heavy exercise to validate your specific form, but see how to reuse validators where they make sense (email, SSN, etc. are easy to reuse).

NTN?

Scott Barnes is Rich Platforms Product Manager - Microsoft.

+3


a source







All Articles