Can Execute of a ICommand while a Context menu open

767 Views Asked by At

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

There are 1 best solutions below

2
On

You should trigger the event ICommand.CanExecuteChanged() from ViewModel which shall cause the Control to invoke CanExecute from ViewModel.