Commands here would be some variation of Josh Smith's RelayCommand (I call mine a VmCommand), and the question is abouthow your ViewModel creates them. I'm aware of two basic techniques, the first being that you set up all command properties inside the constructor, the second being you instantiate the command lazily inside a property getter.
I prefer the latter as I feel it lets me keep my code more organized, as I will typically wrap all behavior related to a given feature in it's own region, as shown below for a SaveCommand.
How do you like to setup your commands?
Cheers,
Berryl
#region Saving
public ICommand SaveCommand
{
get
{
return _saveCommand ?? (_saveCommand = new VmCommand
{
CanExecuteDelegate = x => CanSave(),
ExecuteDelegate = x => Save()
});
}
}
private ICommand _saveCommand;
private bool CanSave() { return IsDirty; }
public void Save()
{
_facade.Save();
}
#endregion