Fernando Cerqueira Web Site
Consultor,Arquiteto de Aplicações,Especialista Microsoft .NET
Sunday, March 14, 2010
ValidatorServices Description and Concept

ValidatorServices is an Set Service Attach to validate of text that can be entered. The service modify the behavior textchanged and/or Leaved to validate and accepts multiple validations for the same element.

For correct operation must define a context of validation that should contain all the elements that are part of the validation process. The service will be controlled by ValidatorMananger that stores the data validation within the scope of application of x defined context.

When the validation fails the default behavior is to paint the border of the red and the error message is displayed in Tooltip.

List of services

NewContext: Sets a validation context.

Validators: Defines a set of validators for the element. It may contain one or more validators.

Behavior: Define the behavior for a set of validators applied to the element.

Element ErrorMessage: Defines an element associated with the set of validators for customizing the presentation of the error message. When associated vivibled property is set to collapse and changed to visibled when an error occurs.

ValidatorManager: It is the manager of the validators in the context.

Samples of Validation
ValidatorManager
The validatorManager is a static object that controls all the validators that are defined in a context.

Note: There can be only one context at a time. When creating a new context the latter is eliminated.

The following methods are available:

GetConextValidator() Returns the FrameworkElement that contains the context of validation

ValidateAll(): Performs validation on the associated control at all entrances of the context.

GetAllErrors(): Performs method ValidateAll() and Return string Array with message erros.

Validate(): Performs validation on the associated control at all entrances of the context in which the group is empty.

GetErrors(): Performs method Validate() and Return string Array with message erros.

Validate(GroupName): Performs validation on the associated control at all entrances of the context in which the group is equal to the parameter passed.

GetErrors(GroupName): Performs method Validate(GroupName) and Return string Array with message erros.

ResetAllValidators(): Performs reset on the all entrances of the context. The property IsValidResult is set to false and border and tooltip are restored to original state.

ResetValidators(): Performs reset on the all entrances of the context in which the group is empty. The property IsValidResult is set to false and border and tooltip are restored to original state.

ResetValidators(GroupName): Performs reset on the all entrances of the context in which the group is equal to the parameter passed. The property IsValidResult is set to false and border and tooltip are restored to original state.

DisabledGroup(GroupName): Performs disabled on the all entrances of the context in which the group is equal to the parameter passed.The property IsValidResult always return true and border and tooltip are restored to original state.

EnabledGroup(GroupName): Performs Enabled on the all entrances of the context in which the group is equal to the parameter passed.

Properties for all Validators
Dependency Properties

Enabled: If false, validator is NOT evaluation. Default value is true. When false, the method Validator always returns true.

PropertyToValidate: Name the property to validation. Default value is empty. Overrider PropertyToValidate in ValidatorCollection Tag. When the value is empty, the validation is permitted for the following types of valid elements :

  • TextBox : Property Text;
  • PasswordBox : Property Password;

When the property contains a value, the validation can be performed on any element and value will be converted to type string.

ErrorMessage: Message displayed when result of validation is false.Default value is empty.

Group: The name of the validation group to which this validation control belongs.Default value is empty.

Read Only Properties

ElementValidator: Framework Element to validation.

IsValidResult: If true, the validation was successful.

Methods for all Validators
Validate(): Method: Performs validation on the associated input control and updates the IsValidResult property