Regarding the problem, both should work really. (one of the comments said it's not bound in the first example, but your code suggests it is. Maybe it has to do with how things are set? In any case, the second approach returns a new one every call, which smells a bit to be honest...
About the where to do it, you can do it either way. I've seen 2 main approaches:
First option:
Have a private ICommand as property, and define it in Constructor:
ctor {
Cool_Command = new RelayCommand<EventArgs>(Execute_CoolCommand,
CanExecute_CoolCommand);
}
public ICommand Cool_Command { get; private set; }
Second option:
Have it as property which is set the first time it's called.
public ICommand CoolAsWell_Command
{
get
{
return _coolAsWellCommand ??
(_coolAsWellCommand =
new RelayCommand<EventArgs>(Execute_CoolAsWell,
CanExecute_CoolAsWell));
}
private set { _coolAsWellCommand = value; }
}
private ICommand _coolAsWellCommand;
Regarding which is better: Which are prettier, redheads, or blonds? :)