我正在尝试按名称将元素绑定到 ContextMenu 中的 MenuItem。要绑定的元素:
<UserControl x:Class="ATCheckerView.TestsPropagate"
x:Name="TestPropagateRoot" ...
工作版本:
<HierarchicalDataTemplate x:Key="SchemTemplate">
<Button Command="{Binding ElementName=TestPropagateRoot, Path=DataContext.vclient.OpenInViewer}" />
</HierarchicalDataTemplate>
非工作:
<HierarchicalDataTemplate x:Key="SchemTemplate">
<TextBlock Text="{Binding path}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="{Binding ElementName=TestPropagateRoot}"
Command="{Binding ElementName=TestPropagateRoot, Path=DataContext.vclient.OpenInViewer}"
CommandParameter="{Binding}" />
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</HierarchicalDataTemplate>