Siverlight Architecture Feedback (Part 2/2)

This article follow the previous one : Part 1

 

We will now detail much more validation integration in the generated context.

How validation is integrated

How validation is integrated

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.
If you link in the Silverlight model package this three classes, you will benefit from validation on client side. This validation model is totally integrated by the Silverlight technology. Setting up the validation in the view by adding “ValidatesOnDataErrors=True”. With this modification, all validation problems will be raised to the user (on update binding). Bonus is to add “ValidatesOnExceptions=True”. You will now raise validations warning on system exception (like conversion problem, setting a string on a float property…)
Binding sample

Binding sample

The last step of this article is exposing what i am generally using in Silverlight/WPF programs. Some of them are from other sources.

Package helpers view

Package helpers view

 Behaviors

  • 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.

Converters

  • 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.

2 Responses

  1. Fabio says:

    Very Very Well.
    In the same manner of “Coding dojo Silverlight” you can try to explain with example on codeplex 😀

    Fabio (Italy)

  2. alphamax says:

    Well i will ask for it to my boss…
    Hope he will be ok 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.