我有一个菜单
,其中每个菜单项
层次结构中的有命令
属性设置为的RoutedCommand
我定义。相关的的CommandBinding
提供了一个回调的评价 CanExecute
控制每个的启用状态菜单项
。
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
.
本的几乎的工作。菜单项初步拿出了正确的启用和禁用状态。然而,当我的 CanExecute
回调使用的数据发生变化,我需要的命令重新请求的结果,从我的回调,以便为这个新状态反映在用户界面。
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.
似乎没有要对的RoutedCommand
或的CommandBinding
这一点。
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).
不是prettiest的书,但你可以使用命令管理无效所有的CommandBinding:
Not the prettiest in the book, but you can use the CommandManager to invalidate all commandbinding:
CommandManager.InvalidateRequerySuggested();
请参阅MSDN