DelegateCommand is not invoked in context menu

前端 未结 3 929
感动是毒
感动是毒 2021-01-25 11:13

I can`t seem to get this right click popup menu to work.



        
3条回答
  •  忘掉有多难
    2021-01-25 11:50

    You can't use a RelativeSource Binding to access the TreeView.DataContext from the ContextMenu because it is not in the main UI visual tree. This is a very well documented problem and the solution is to pass the DataContext object through to the ContextMenu using the ContextMeny.PlacementTarget property and the Tag property on the object that has the Contextmenu applied to it.

    Having already written and re-written about this many times, nowadays, I much prefer to request that you read my answers to the ContextMenu.PlacementTarget is not getting set, no idea why and Add context menu in datagrid, how to get the select Item value questions here on Stack Overflow for full explanations and code examples. If you need further help, just search the internet for 'WPF ContextMenu DataContext' or something similar and you should find dozens of tutorials on this exact topic.

提交回复
热议问题