I have a View with multiple Buttons and just as many Commands. For every Command I think I will have to implement ICommand. My program will contain a statemachine, so it will be possible that the CanExecute of the Commands will change run-time.
The only implementation example of the CanExecuteChanged is this:
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
But here it is stated that this implementation is a bad solution. RaiseCanExecuteChanged() should be used.
But I cannot find a proper implementation of the CanExecuteChanged with RaiseCanExecuteChanged. Here I find a basic example, but the user states it
is a very simple implementation (which will probably throw a NullReferenceException occasionally)
I prefer code that doesn't throw exceptions once in a while. Does someone have a better example?