MVVM datatemplate 下button.contextmenu的command 失效解决方案

时间:2022-10-05 00:36:29
 <Button CommandParameter="{Binding}"
Tag="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type pagesView:OutputPage}}}"
Command = "{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type pagesView:OutputPage}}, Path=DataContext.EditOutputCommand}">
<Button.ContextMenu>
<ContextMenu>
<MenuItem Header="削除"
CommandParameter="{Binding}"
Command="{Binding Path=PlacementTarget.Tag.DataContext.DeleteCurrentLineCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}}"/>
</ContextMenu>
</Button.ContextMenu>
</Button>

button.contextmenu的command 失效;

参考地址:http://*.com/questions/9994241/mvvm-binding-command-to-contextmenu-item