I need to refresh the CanExecute
state of one or more (though by far not all) RoutedCommand
objects.
I know that you can update all commands by using
CommandManager.InvalidateRequerySuggested();
Since this updates far more commands than necessary, calling this function is sometimes a performance problem in my application.
My initial hope was that calling CanExecute()
manually would also raise the event if the state changed, but this is not the case.
When looking at the reference source then, the CanExecuteChanged
does not seem to be accessible for derived classes to provide some kind of extension to the RoutedCommand
class that allows raising the event manually.
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
Any ideas how I could implement such a mechanism? I know about DelegateCommand
, but I need a routed command, so I don't think this class can help me.