Bind ContextMenu's MenuItem visibility to ListView selection

99封情书 提交于 2019-12-04 05:37:43

The problem is that the ContextMenu is not in the same visual tree as the ListBox, therefore bindings don't find the ListBox. If you bind against PlacementTarget, that should do the trick:

<MenuItem Header="Open"
    Visibility="{Binding RelativeSource={RelativeSource FindAncestor,
        AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem,
        Converter={StaticResource valueToVisibility}}" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!