Is it possible to have CommandManager requery only specific WPF command instead of all?

Posted by aoven on Stack Overflow See other posts from Stack Overflow or by aoven
Published on 2010-03-23T10:18:29Z Indexed on 2010/03/23 10:23 UTC
Read the original article Hit count: 358

Filed under:
|
|
|

I'm trying to implement a highly responsive UI for my MVVM application, so I've chosen to have all command handlers automatically execute in a BackgroundWorker so they don't block the UI.

But at the same time, I don't want the user to be able to execute the same command while it is still executing in the background. The solution seems obvious:

  1. When Executed handler is invoked, have the CanExecute handler return false
  2. Start the BackgroundWorker async
  3. When BackgroundWorker finishes, have the CanExecute handler return true again.

Problem is, I need to notify WPF after step 1 and again after step 3 that CanExecute has changed and that it should be required. I know I can do it by calling CommandManager.InvalidateRequerySuggested, but that causes CanExecute handlers of all other commands to be requeried as well. Having a lot of commands, that's not good.

Is there a way to ask for requery of a specific command - i.e. the one that is currently being executed?

TIA

© Stack Overflow or respective owner

Related posts about wpf

Related posts about mvvm