In my app, I’d like to make the context menu of a button appear when the user left clicks on the button. I can do this by creating an event handler for button’s click event and then setting it’s context menu’s IsOpen property to true, but I’m wondering if there’s a pure xaml solution to do the same thing. Any ideas?
Thanks!
You can create a new template for the button and then provide a context menu in the template’s visual tree. Something like this:
You could then trigger using the
IsPressedproperty of the button and hook it up using a setter with contextMenu as theTargetName.My real question is, what are you using this for? Opening a context-menu on left-click is going to be inherently flawed, because context-menus, by their nature, close when any other element is clicked. Which means this trigger, even when properly set up, will simply open and close the context menu immediately. I am curious as to why you need this kind of behavior; perhaps there is a better way of doing it than using a context-menu.