我試圖從用戶控件的列表視圖中使用上下文菜單,但命令未觸發(在需要時不啓用/禁用)。從用戶控件觸發上下文菜單不起作用
代碼:
<UserControl ....
<UserControl.Resources>
<ContextMenu x:Key="SharedInstanceContextMenu">
<MenuItem Header="Edit" Command="{Binding ElementName=UC, Path=DataContext.EditSelectedItemCommand}" CommandParameter="{Binding}"/>
</ContextMenu>
<Grid ...>
<ListView ....>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}"/>
<Setter Property="ContextMenu" Value="{StaticResource SharedInstanceContextMenu}"/>
</Style>
</ListView.ItemContainerStyle>
如何使命令點火(和啓用/禁用,命令行爲的一部分)?
(順便說一句,這個問題似乎類似於Treeview context menu command not firing但嘗試所有的解決方案有它仍然無法正常工作後)。
很難說沒有看到你的視圖模型 - 也許你可以刪減一個小例子(這實際上也可以幫助你)。 – NSGaga 2012-04-18 23:41:49
你試過這個嗎? :http://stackoverflow.com/questions/3011184/wpf-menu-items-only-bind-command-parameters-once/9769583#9769583 – 2012-04-19 06:09:17