I am trying to understand what is happening with ContextMenu. I know that this appears as a separate window with a separate visual tree, so we cannot use relative binding to bind a command open as a property of a user control. For example, the following does not work :
<MenuItem Command="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=TestCommand}" Header="Test" />
But if you set the data context of the user control to a view model that provides the command as a property, the following will work:
<MenuItem Command="{Binding TestCommand}" Header="Test" />
I do not understand how ContextMenu inherits the value of a DataContext if it is not part of the visual tree. I expect both of these examples to behave the same way (i.e. both work or both fail).
source share