MVVM下鼠标右键菜单命令通过桥接的方式绑定上下文
<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>
作者:猫叔Vincent
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。