My Session at MIX11: Effective Validation Techniques with MVVM in Silverlight

MIX11_BB_I'mSpeakingAt_2I’m really happy to announce that I’ll be presenting at the MIX’11 Conference in Las Vegas! I will be talking about how to implement decent validation in Silverlight when using the MVVM pattern.

Here is the link form my presentation: http://channel9.msdn.com/events/MIX/MIX11/OPN05

Now what I want is to provide you with the most accurate and most important details about this topic. So here is your chance to have an impact on this session. Tell me about the scenarios that are really crucial for you in you application and for which you’d love to see a solution. Here are some details (just some bullet points) I plan to include my presentation:

  • Attribute based validation
  • Correct implementation of IDataErrorInfo and INotifyDataErrorInfo in a ViewModeBase
  • Issues when binding directly to the Model
  • Async Scenarios (client and server side validation),
  • Dependency on other properties and complex objects
  • Doing Validation when Binding doesn’t happen (required fields without ever gaining focus)
  • Notifying the ViewModel about wrong input (Input is not in a correct format (+a tip on how to “localize” it))
  • Customizing Validation Feedback with VisualStateManagement + Blend
  • Custom states +a couple of nice behaviors to push the view in invalid state
  • Life without INotifyDataErrorInfo (validation in WP7)

So if there is something you’d wish to hear about just ping me!

Advertisements

22 thoughts on “My Session at MIX11: Effective Validation Techniques with MVVM in Silverlight

  1. hello nice to listen that Validation with MVVM is going to be a part of MIX11 Zoltan kindly show us how can we validate user input at client with notiication because untill and unless we not provide a custom validation class we cannot control the user input inside MVVM beacuse use state is persist on error so we need such kind of stuff i hope you understand my question and iam looking forward for your session…

  2. Hi zoltan nice and very unique session on validtion great and i need same kind of structure with RIA Serivice would you please help me how can i tackle the validationErros on client without SubmitChanges onto server using MVVM.

    Regards
    Atif

    • Hi Atif,
      I’m happy you like the session. So you want your entities to validate on the client side using RIA Services? Well, you have property validation by default, since RIA entities use attributes on properties and on classes to perform validation. So if you expose these entities on the UI, datagrid and dataform should be okay with it… Well if you want to expose only your mvvm model, but use the attributes over the ria entity properties, well then you should override the validatateproperty method in the viewmodel, (the one i created) and modified the code just a little bit, to perform validation on the selected properties of the selected mvvm properties, instead of the mvvm properties themselves… also you could automate this using a custom attribute over these properties… Hope this hepls… if you need more help, post a sample scenario, what and how you want it to work, and i’ll show you a sample code or a sample architecture…

  3. Zoltan i did my property level validation inside my Domainservice Metadata class and its all goddd but what i want that when user save any data from silverlight client so MVVM first check the validation error on client and then if all fine then submitchanges to server this is what actually i want , what i do is to catch the submit operation then i got all the validation errors but i dont want to submit if is there any validation error in entity so Zoltan this is the stuff i want i hope you understand my problem and i hope you got the solution.

    Regards
    Ati

    • Hi Atif!

      You kind of copy pasted my answer here 🙂

      Anyway:

      I was curious about the client side… You use a DomainDataSource class in you xaml or a DomainContext in mvvm?

      If your are using DDS than don’t do that 🙂

      If not…

      You have a Submit method in your viewmodel, which calls SubmitChanges… In this method before you call submitchanges call your validation logic.

      Now about the validation logic… on the client side you don’t have metadata classes… that exists only on the server side… on the client side the attributes are placed over the properties of the original entitiy.

      Now you have the validateproperty method in the viewmodel. Override it… See the code I posted on my blog for the session and rewrite that part where I use Validator.TryValidateProperty(this…..) instead of “this” you should add the ria entitiy you want to validate…

      That’s it… I hope it’s clear!

  4. Hi Zoltan, great presentation, I have learnt alot from it, Just downloaded your sample and run the 1st app which uses the ValidationHelperBehavior. In the Age textbox, instead of putting in a numeric num, I put text.

    However, I noticed the custom ErrorMessage (alma) that you specified in the Xaml never got picked up by the Age TextBox. It ALWAYS shows “input is not in a correct format”. It seems like the TextBox TOTALLY ignore the error return from the INotifyDataErrorInfo.GetErrors

    I wonder if there is a way to override the “input is not in a correct format” message in the case of FormatException?

    • Hi!

      Yes, it does not. All you can do is stop the default error message to show up… which is kind of a bmmer… what you can do is to use a different type of property… like a string. Unfortunately there is no way to inject your own custom error message

      • Thanks for confirming my findings. Looks like to only way to localize the error message is to have conversion happened inside the ViewModel and capture the error or exception there.

  5. Hi Zoltan! I really enjoyed your talk at MIX. Finally a solid way of implementing validation. I wish more speakers used code snippets instead of typing code in front of an audience. It really kept the pace up. Very cool. I was just wondering if I could get the source code from your demo? That would be awesome, thanks!

  6. Hi Zoltan, The link deosn’t have the video.. After seeing your slides i’m very eager to see the talk,,,, Can you provide any link other than that…

  7. I’m working in Prism4.1 & Silverlight 5 How can use these techniques in my project? can I download sample code of it ? any location please let me know?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s