Since the Popuup control has it's separate visual tree, you cannot use find ancestor to find the Grid. The trick here is to use the PlacementTarget property, that contains the element, the ContextMenu is aligned to, what is the Grid in our case. But…
场景:ListBox中有个ContextMenu,希望点击其中一个菜单项的时候把ListBox当做CommandParameter传递给Command,但是发现无论是通过ElementName还是RelativeSource中的FindAncestor传值,命令接收到的参数一直都是null. 分析:通过网上查找,找到这么一句话“The problem is that the ContextMenu is at the root of its own visual tree, so any Rel…