This article follow the previous one : Part 1
We will now detail much more validation integration in the generated context.
Here is a schema that summarize the validation integration.
- The generated part (left side) is the MVVM DTO, processed from the edmx file. This file will be linked in the model in silverlight side. This part is absolutely not correlated with validation.
- The other partial class (right side) is added by user and can embed multiple information (extra properties, methods, …) and, in this case, flag the class and say it can be validated.
- The last part (below) is the validation definition. You can embed each rule in the constructor of the class.
The last step of this article is exposing what i am generally using in Silverlight/WPF programs. Some of them are from other sources.
- BindVisualStateBehavior : Link an enum property of your VM and, on changes, invoke a “change state” in the view. The main goal is to define a Laoding/Loaded state, an Error/NoError state, an Application state and allow user to orchestrate your silverlight application only by changing an enum value.
- BackToStateBehavior : On a specific action, set an enum to a specified binded property.
- KeyPressSelecterComboboxBehavior : On a user letter key press , select combobox item starting by the item.
- NotNullCheckboxBehavior : When someone set null to a checkbox, it will automatically be modified to false. Fighting against bad database format 🙂
- RadioButtonToValueBehavior : When a radio is checked, set the specified value to a linked property. Usefull to link radio button group to value.
- SecurityBehavior : This behavior is linked to a list of “Role” and, if a specified role is not found in the list, it hides the associated object.
- UpdateBindingOnTextChangedBehavior : On each key press, update the text binding.
- ValueToVisibilityBehavior : Only show the associated object if a linked property is equal to a specified value.
- BirthDateConverter : A simple converter to change a DateTime to a specified format.
- VisibilityConveter (& Inverted version) : Convert a boolean to visibility
- VisibilityFromDataConverter (& Inverted version) : Test if the data is null and transform the result to visibility.