I have a button with a default command and a context menu for other available commands:
<Button Content="Do this" Height="23" Width="75" Command="local:MyCommands.ThisCommand"> <Button.ContextMenu> <ContextMenu> <MenuItem Header="Do this" Command="local:MyCommands.ThisCommand" /> <MenuItem Header="Do that" Command="local:MyCommands.ThatCommand" /> </ContextMenu> </Button.ContextMenu> </Button>
By default, the context menu appears starting at the hot spot of the cursor:
However, I'd like it to appear at a fixed relative position, beneath the button (fake, edited screenshot):
Setting the context menu's Placement
, PlacementRectangle
and PlacementTarget
properties doesn't seem to do anything; the context menu insists on hanging off the cursor wherever I right-click my button. Worse, focusing the button and hitting the menu key causes the context menu to sit in front of the button, blocking it completely.
So, how exactly do I specify that the context menu should appear beneath the button?
A context menu (also know as a contextual menu, shortcut menu or pop-up menu) is the menu that appears when you right-click and offers a set of choices that are available for, or in context of, whatever it was you clicked.
The contextmenu event fires when the user attempts to open a context menu. This event is typically triggered by clicking the right mouse button, or by pressing the context menu key.
A context menu is a pop-up menu that provides shortcuts for actions the software developer anticipates the user might want to take. In a Windows environment, the context menu is accessed with a right mouse click.
A context menu is a menu in a GUI that appears upon user interaction, such as a right-click mouse operation. A context menu offers a limited set of choices that are available in the current state, or context, of the operating system or application.
Check out Remarks under ContextMenu.Placement
and try this
<Button Content="Do this" Height="23" Width="75" ContextMenuService.Placement="Bottom" Command="local:MyCommands.ThisCommand"> <Button.ContextMenu> <ContextMenu> <MenuItem Header="Do this" Command="local:MyCommands.ThisCommand" /> <MenuItem Header="Do that" Command="local:MyCommands.ThatCommand" /> </ContextMenu> </Button.ContextMenu> </Button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With