数控机床网站建设,做书一般在哪个网站下载素材,仿制app软件多少钱,网站建设服务公WPF中ContextMenu(右键菜单)使用Command在部分控件上默认为灰色的处理方法 原文:WPF中ContextMenu(右键菜单)使用Command在部分控件上默认为灰色的处理方法问题描述 今天发现如果我想在一个TextBlock弄一个右键菜单,并且使用Command绑定,结果发现默认菜单式不可用的. 问题原因… WPF中ContextMenu(右键菜单)使用Command在部分控件上默认为灰色的处理方法 原文:WPF中ContextMenu(右键菜单)使用Command在部分控件上默认为灰色的处理方法 问题描述 今天发现如果我想在一个TextBlock弄一个右键菜单,并且使用Command绑定,结果发现默认菜单式不可用的. 问题原因 这个问题不知道算不算BUG,反正如果是在一个不可获得的焦点的东西上面使用ContextMenu,CanExecute的事件路由就会停止在ContextMenu,就没办法到达窗体上.一个解决的方案是吧CommandTarget设置到窗体上去. 事例代码 Window x:ClassTestPopupMenuCommand.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlTitleMainWindow Height350 Width525Window.CommandBindingsCommandBinding CommandClose ExecutedCloseCommand/CommandBinding CommandNew ExecutedNewCommand//Window.CommandBindingsGridTextBlockTextBlock.ContextMenuContextMenuMenuItem CommandNew CommandTarget{Binding PathPlacementTarget,RelativeSource{RelativeSource AncestorTypeContextMenu}}/MenuItem CommandClose//ContextMenu/TextBlock.ContextMenutest/TextBlock/Grid
/Window代码分析 里面的两个菜单项,New的是可用的,Close默认是不可以用的.因为我把New的CommandTarget修改了. 里面具体的command实现代码我就不贴了. posted on 2019-04-05 00:18 NET未来之路 阅读(...) 评论(...) 编辑 收藏 转载于:https://www.cnblogs.com/lonelyxmas/p/10657682.html