When does WPF decide to execute commands that they can execute?

When WPF commands ask if they can execute? The debugger reports that this happens quite often. But what is the exact set of conditions?

+4
source share
1 answer

TL version; DR is that CanExecute methods are called when certain input events occur in a window. There are primarily keyboard and mouse events.

Therefore, at any time, someone presses or presses a key, ALL commands become invalid CommandManager (by raising CommandManager.RequerySuggested ). This is why it is important to quickly save CanExecute methods.

You can also handle this by creating your own implementation of ICommand , which does not use the CommandManager for the CanExecuteChanged event.

0
source

All Articles