I have a ContextMenu in a TreeView
UserControl (DataContext=ViewModel)
|
|
---- TreeView (ItemSource=MyItems)
|
|
Finally, after many many many google searches I ran into the solution
<MenuItem
Header="Exclude season"
Command="{Binding DataContext.MyRelayCommand, Source={x:Reference _myTreeView}}" />
Because the HierarchicalDataTemplate does not appear in the visual tree, there is not "relative" source...
I hope this helps somebody else who's pulling his/her hair out...
Another commonly used solution:
<ContextMenu DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.DataContext}" />