Monday, February 7, 2011

MVVMLight Extensions, Part: The Snippets


MVVMLight is great. It is at the very least the most effective MVVM framework that is Blend / Visual Studio Design time friendly. The project focuses a lot on providing the minimum amount of built in functionality to give you the ability to make effective MVVM applications. This means that there are some areas (like validation) where MVVMLight does not add anything more that what is already available with WPF / Silverlight. So wanting to extend the library with your own extensions is a normal desire. 


Here is my attempt. You don't have to use it. I don't expect you to (you might want to add the code to your bag o tricks in your own mvvmlightextensions).

The snippets can be categorized by Model and General: 

General
mvvmrc
For mvvm relay command expansion shown, Just fill in name / ExecuteFunction and CanExecuteFunction: 

Utilized in sample:

mvvminpcs:
For INotifyPropertyChanged using stacktrace: 
The RaisePropertyChanged function is defined in ViewModelBaseEx and therefore your ViewModel/Model needs to inherit from ViewModelBaseEx 
Used in sample application: 
Model
mvvmde:
If you Model inherits from ViewModelBaseEx you can use mvvmde for the data validation logic: 
Just fill in the property , the validation condition and the error message you want displayed.
For additional properties just use the mvvmdei snippet:


Used in the sample application: 






No comments:

Post a Comment