May 2nd, 2013, 09:06 AM
How to make a button show a contextmenu by mouse left click only?
I want to show a contextmenu filled with databound items when the user left clicks a button.
I have tried this code in this post:
I used the last xaml post, but sadly this is only working for non Binding context menus. WHen adding menuitems like the author does its working perfectly. When I bind the context menu to an items source, I have to FIRST right click to show items, THEN left click and the same context menu appear with items. If I click left button first, the context menu is empty. I can't figure out why??
So, I need help with:
1) Create a button with a context menu that is visible ONLY when clicking left mouse button (by def this is not a context menu but whatever works for my customer, and I don't have to write a whole new control just for this...)
2) Make it work in a MVVM project, no code in the code-behind file, only in viewmodel
3) How can I bind commands so I can in the viewmodel access the object that was clicked on in the context menu. For example, if I bind a collection of Person objects to the context menu, if the user select the menu item with Person=Donald, I want in the viewmodel a reference to Donald so I can work with it. How is this possible? I should be able to pass a CommandParameter from view to viewmodel?
But how do I hook it up?
kind regards from someone who is learning WPF the hard way, implementing new functionality to a 10000 lines of code application...
Click Here to Expand Forum to Full Width
Survey posted by VBForums.