The context menu is not part of the same visual tree. Ancestor bindings do not work, because the context menu is not a child of the element on which it is included; in your case a datagrid.
There are some workarounds, Ive answered this question earlier here and here (view)
But what you are looking for is a placement target to do something like this (as long as AddDividerCommand is a property in a datagrid (i.e. placement target)
<ContextMenu DataContext="{Binding RelativeSource={RelativeSource Mode=Self}, Path=PlacementTarget}"> <MenuItem Header="Add Divider" CommandParameter="{Binding Path=SelectedIndex}" Command="{Binding Path=AddDividerCommand}"/> </ContextMenu>
source share