You can use the TextBlock tag to refer to the DataContext TreeView, then you can get it inside ContextMenu using relative source binding via PlacementTarget , for example:
<TextBlock Text="{Binding Name, Mode=OneWay}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeView}}"> <TextBlock.ContextMenu> <ContextMenu DataContext="{Binding PlacementTarget.Tag, RelativeSource={RelativeSource Self}}"> <MenuItem Header="{Binding Test}"/> </ContextMenu> </TextBlock.ContextMenu> </TextBlock>
If you want to keep the original DataContext of the context menu, you can directly go to the properties using full path binding, for example:
<TextBlock Text="{Binding Name, Mode=OneWay}" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=TreeView}}"> <TextBlock.ContextMenu> <ContextMenu> <MenuItem Header="{Binding PlacementTarget.Tag.Test, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/> </ContextMenu> </TextBlock.ContextMenu> </TextBlock>
source share