Data validation is an important part of any application. If you've written code to validate data in Silverlight applications prior to the release of Silverlight 4, you've probably discovered that there isn't a great way to ensure that data is entered correctly and errors displayed properly by controls. The typical technique used for validating data was to throw exceptions within property setter blocks as data was found to be invalid. Controls bound to a property could be notified of a data validation exception by setting ValidatesOnExceptions to true in the data binding. Although this technique certainly works, there are some new options available in Silverlight 4 that can be used without resorting to throwing exceptions.
I’ve had the opportunity to give a lot of presentations on the Model-View-ViewModel (MVVM) lately both publicly and internally for companies and wanted to put together a post that covers some of the frequent questions I get on commanding. MVVM relies on 4 main pillars of technology including Silverlight data binding, ViewModel classes, messaging and commanding. Although Silverlight 4 provides some built-in support for commanding, I’ve found that a lot of people new to MVVM want more details on how it works and how to use it in MVVM applications.
I had the opportunity to give a 1-day workshop covering new Silverlight 4 features at the TechReady conference on Microsoft’s Redmond campus this weekend and wanted to post some of the sample code shown for the people who attended and anyone else who’s interested. The workshop was based on the free Silverlight LOB course Microsoft put together which has a lot of detailed lab exercises and videos available if you haven’t seen them. The demo code covers many of the topics detailed in the What’s New in Silverlight 4 whitepaper that John Papa put together.