赞
踩
前几天写遇到一个在ListBox加ContextMenu,给MenuItem设置Command,但是当程序在CanExecute为true的情况下,MenuItem任然为灰色不能执行,有操作之后能执行
把执行的地方换成Click事件是没有问题的,困扰了我一段时间,再加上网上查阅的资料,大致知道了情况:
在不能获得焦点的控件上面使用ContextMenu,CanExecute的事件路由就会停止在ContextMenu,就没有办法到底窗体上
解决办法:
1.在MenuItem上设置CommandTarget
CommandTarget="{Binding Path=PlacementTarget,RelativeSource={RelativeSource AncestorType=CotextMenu}}"
2.把CommandBinding放在ContextMenu里面
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。