Why can't I use DataContext={Binding} for my context menu?

后端 未结 1 965
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 08:23

I have code that looks something like this:



        
相关标签:
1条回答
  • 2020-12-21 09:06

    First of all, DataContext="{Binding}" does not make much sense as that would bind the DataContext to the DataContext. The problem here is probably that the ContextMenu is not in the logical tree, and its visual tree is disconnected since ContextMenus are floating popups.

    Try binding the DataContext via the PlacementTarget:

     DataContext="{Binding PlacementTarget.DataContext,
                           RelativeSource={RelativeSource Self}}"
    
    0 讨论(0)
提交回复
热议问题