MVVM下鼠标右键菜单命令通过桥接的方式绑定上下文

发布时间 2023-05-08 10:06:14作者: 猫叔Vincent
<Grid Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}}">
 <Grid.ContextMenu>
  <ContextMenu>
    <MenuItem
      Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ContextMenu}}, Path=PlacementTarget.Tag.DataContext.ExtractToSubGraphCommand}"
      CommandParameter="{Binding}"
      Header="提取" />
  </ContextMenu>
 </Grid.ContextMenu>
</Grid>