[英]How to pass an index of a selected context menu item to a bound command?
How could i bind all context menu items to one single command, which gets the index of the menu item called? 我如何将所有上下文菜单项绑定到一个命令,该命令将获得菜单项的索引? I have a WPF/MVVM project. 我有一个WPF / MVVM项目。
<ContextMenu x:Key="cm" ItemsSource="{Binding ActionItems}"
DisplayMemberPath="ActionDescription">
</ContextMenu>
Your should pass it as a CommandParameter
: 您应该将其作为CommandParameter
传递:
<ContextMenu x:Key="cm" ItemsSource="{Binding ActionItems}" DisplayMemberPath="ActionDescription"
Command="{Binding YourCommand}" CommandParameter="{Binding YourParameter}">
...
</ContextMenu>
Updated you need the solution described here: MVVM binding command to contextmenu item 更新后,您需要这里描述的解决方案: MVVM绑定到contextmenu项的命令
Updated after comments 评论后更新
relapse - than you should implement it as shown here: WPF ContextMenu with ItemsSource - how to bind to Command in each item? 复发-比您应该按以下所示实现它: 带ItemsSource的WPF ContextMenu-如何在每个项目中绑定到Command? . 。 Please notice that link is a duplication of other question. 请注意,该链接是其他问题的重复。 So read the both please. 所以请阅读两者。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.