Use the Placement and PlacementRectangle properties of your ContextMenu.
In this example below, I set the Placement property to "Relative" and the Rectangle to x, y coordinates 25, 25. Then, no matter where I click, the context menu will appear at 25, 25, relative to the button.
<Button ContextMenuService.Placement="Relative" ContextMenuService.PlacementRectangle="25, 25, 0, 0"> <Button.ContextMenu> <ContextMenu> <MenuItem Header="Do this" /> <MenuItem Header="Do that" /> </ContextMenu> </Button.ContextMenu> </Button>
Of course, you could do a more dynamic calculation of the values ββthat will be used for these properties, depending on the size of the menu and its proximity to the edge.
Gordon true
source share