DelegateCommand class for Windows Phone 7 and 8

First off, I did not author this from scratch.  Instead, I added some functionality to this class that WindowsPhoneGeek published. I wanted to add CanExecute() and Execute() methods that take no parameter.   Most of the commands I use in my MVVM apps tend to be based on the state of the ViewModel anyway and thus I do not need the parameters.

Here is the DelegateCommand.cs class and the cmds snippet that lets you quickly add a command to any ViewModel.

      

Command code would look like the following:

The code for the DelegateCommand.cs looks like this:

Leave a Reply

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