Can Execute of a ICommand while a Context menu open

我是研究僧i 提交于 2019-12-23 01:59:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!