UI Validation
Download Source Code The validation provides 2 functions:
|
Below is the OrderView where the Save button is disabled with the validation message:
The button is disabled based on the Validation.HasError property of the textboxes in the OrderView.xaml:
The button is disabled based on the Validation.HasError property of the textboxes in the OrderView.xaml:
To perform the validation on the textboxes we set the ValidatesOnDataErrors, NotifyOnValidationError, and UpdateSourceTrigger properties:
The PropertyChanged value of the UpdateSourceTrigger means that validation is performed on every keystroke in the textbox. We define the UI to show when an error happens in ValidationStyle.xaml:
Notice that we set the Quantity property of the OrderViewModel to string instead of int, this is so that we can display a more user friendly message when a non-integer is entered instead of the default message on casting which is not very intuitive to a regular user.
Next we will show you how to open windows within the MVVM pattern.
Open New Window
The PropertyChanged value of the UpdateSourceTrigger means that validation is performed on every keystroke in the textbox. We define the UI to show when an error happens in ValidationStyle.xaml:
The AdornedElementPlaceholder shows the control being validated, and the ErrorContent is the validation message string.
The validation check is done in the ViewModel by implementing the IDataErrorInfo interface:
In the implementation of the IDataErrorInfo interface we specify the message to display based on the condition:
The validation check is done in the ViewModel by implementing the IDataErrorInfo interface:

In the implementation of the IDataErrorInfo interface we specify the message to display based on the condition:
Notice that we set the Quantity property of the OrderViewModel to string instead of int, this is so that we can display a more user friendly message when a non-integer is entered instead of the default message on casting which is not very intuitive to a regular user.
Next we will show you how to open windows within the MVVM pattern.
Open New Window
Future series of articles on sharepoint:
- sharepoint list -- the concepts of sharepoint list and how to effectively manage it
sharepoint version control -- the internals of sharepoint version control and how to administer and manage the versions
sharepoint permissions -- how to manage the permissions in a large enterprise sharepoint environment
sharepoint server farm -- how to set up a high availability sharepoint server farm
sharepoint document library -- the details on how to get your ways around the document library in sharepoint
sharepoint configuration -- the configurations needed for different sharepoint network scenarios
sharepoint css -- making the most out of customizing sharepoint frontend
sharepoint web services -- some of the most convienent ways to communicate with the internals of sharepoint