Friday, August 19, 2011

Forcing validation for required fields in Silverlight - CodeProject

Silverlight LogoImage via WikipediaIntroduction to Article

The common practice in Silverlight, when using MVVM, is to validate user data via the bound property setter in the view model. Although this works well for most circumstances, it doesn't work when the user doesn't make a change to data and instead clicks on a button. For example, imagine a form that prompts the user for his/her name, which must not be blank, and then click a Next button. If the user just clicks the Next button without typing anything in the Name field, the validation via the bound property setter is never executed.
One way to address this is to repeat the validation in the view model when the user clicks Next. The issue with this is how to display the error message to the user in a way that is consistent (e.g. shown in a ValidationSummary and red tool tip, with any other error).



Forcing validation for required fields in Silverlight - CodeProject
Enhanced by Zemanta

No comments: