A quite simple and straightforward example.
I have a window. It has CommandBindings set to catch a RoutedUICommand execution.
<Window
...
>
<Window.CommandBinding>
<CommandBinding
Command="{x:Static local:Commands.Command1}"
Executed="OnCommand1Executed"
CanExecute="OnCanCommand1Execute"
/>
</Window.CommandBinding>
</Window>
There's a UserControl hosted in the window, inside of which a ContextMenu is declared. A ContextMenu item has the Command property assigned to the same RoutedUICommand.
<ContextMenu>
<MenuItem Command="{x:Static local:Commands.Command1}" />
</ContextMenu>
But the menu item remains inactive (== disabled). Somehow command execution doesn't go up to the window. Maybe it's because ContextMenu is inside of a popup?
Everything works properly if I add needed CommandBinding into the ContextMenu.CommandBindings collection. But that's a terrible option to not have a place for a single 'global' CommandBinding.
How can I solve the problem in the best way?
UPD: Turns out it's not that bad. The Commands aren't bound only at the first time user opens the menu. If it's closed and reopened everything's fine. Still, it seems to be not desirable and a quite weird behavior.