问题
A Control has its ContextMenu
and its MenuItem
is bound to an ICommand
. ICommand's Can Execute has some code to enable and disable the MenuItem
. This hits while loading and checks for Can Execute but it can hit while open the ContexMenu
and it need to be hit(Checks) for each time while opening the ContextMenu
.
<Border>
<Border.ContextMenu>
<ContextMenu>
<MenuItem Command="{Binding SaveCommand, Source={StaticResource vm}}" CommandParameter="{Binding}" Header="Menu1" />
</ContextMenu>
</Border.ContextMenu>
</Border>
How could be done this. Any idea?
回答1:
You should trigger the event ICommand.CanExecuteChanged() from ViewModel which shall cause the Control to invoke CanExecute from ViewModel.
来源:https://stackoverflow.com/questions/18118368/can-execute-of-a-icommand-while-a-context-menu-open