我的 xaml 中有以下 ContextMenu:
<ContextMenu ItemsSource="{Binding RSPContextMenuCommands}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="CommandParameter" Value="{Binding}" />
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=DataContext.ShowASPCommand}" />
<Style.Triggers>
</DataTrigger>
<DataTrigger Binding="{Binding SpName}" Value="ASP">
<Setter Property="Header" Value="Show Additional Service Providers" />
<Setter Property="Command" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=DataContext.TransferCommand}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContextMenu.ItemContainerStyle>
<ContextMenu.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="5,0,0,0" Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}, Path=PhoneNumber, PresentationTraceSources.TraceLevel=High}" />
</StackPanel>
</DataTemplate>
</ContextMenu.ItemTemplate>
</ContextMenu>
其中,RSPContextMenuCommands是 Schedule(class) 类型的集合。Schedule 中有PhoneNumber属性。TransferCommand与声明 RSPContextMenuCommands 的级别相同。我得到 ShowASPCommand 和 TransferCommand 但不是PhoneNumber。我尝试了各种 RelativeSource 组合,但没有奏效。什么应该是它的正确RelativeSource。也试过RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PhoneNumber