Here is what I do when writing MVVM application.
Create class that will handle your commands (this is just a quick sample):
class CommandHandler:ICommand
{
private Action action;
private Func<bool> isEnabled;
public CommandHandler(Action _action, Func<bool> _isEnabled)
{
action = _action;
isEnabled = _isEnabled;
}
public bool CanExecute(object parameter)
{
return isEnabled();
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
action();
}
}
Now under you ViewModel, you have to create tow things:
1) Create method that you will call with your button click like the following
Public void ButtonWasClicked()
{
//do something here
}
2) Create actual command
private ICommand _cmd_MyCommand;
public ICommand cmd_MyCommand
{
get { return _cmd_MyCommand ?? new CommandHandler(ButtonWasClicked, new Func<bool>(() => true)); }
}
and finally under your View (WPF window) you can bind the command like this:
<Button Command="{Binding cmd_MyCommand}">
Obviously, there are also other methods how you can use with Commands in WPF (e.g. some folks might suggest RelayCommand). This may seem a bit strange in the beginning (why so much trouble for a simple button click), but you will get into it really quickly once you start using them.
Here is some nice video on MVVM commands that I used in the past as well: http://www.youtube.com/watch?v=EpGvqVtSYjs
Good luck!
ItemsControl.