views:

1098

answers:

1

I have a Menu where each MenuItem in the hierarchy has its Command property set to a RoutedCommand I've defined. The associated CommandBinding provides a callback for the evaluation of CanExecute which controls the enabled state of each MenuItem.

This almost works. The menu items initially come up with the correct enabled and disabled states. However when the data that my CanExecute callback uses changes, I need the command to re-request a result from my callback in order for this new state to be reflected in the UI.

There do not appear to be any public methods on RoutedCommand or CommandBinding for this.

Note that the callback is used again when I click or type into the control (I guess it's triggered on input because mouse-over doesn't cause the refresh).

+8  A: 

Not the prettiest in the book, but you can use the CommandManager to invalidate all commandbinding:

CommandManager.InvalidateRequerySuggested();

See more info on MSDN

Arcturus
Thanks this worked just fine. There's a slight delay in the UI, but I'm not too worried about that. Also, I up-voted your answer immediately, then took the vote back to see whether it worked. Now that it's working, I can't re-apply the vote again. Not sure why SO has that rule in place.
Drew Noakes
I edited your answer in order to re-apply my vote. I didn't change anything in the edit. Thanks again.
Drew Noakes
haha ok :) thanks!
Arcturus