Try:
<ContextMenu x:Key="ContextMenu.TreeView">
<MenuItem Command="{Binding AddNodeCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ContextMenu}},
Path=PlacementTarget.SelectedItem}"
Header="Add Node" />
<MenuItem Command="{Binding DeleteNodeCommand}"
CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type ContextMenu}},
Path=PlacementTarget.SelectedItem}"
Header="Delete Node" />
</ContextMenu>
Contextmenu
is not part of the same Visual tree as the TreeView
it links against. So we need to use the PlacementTarget
to route to the TreeView
accordingly.