I have a rectangle.The rectangle
has a custom contextmenu
(just some simple changes made within the ControlTemplae
of <ContextMenu.Template>
).What i want is,on left mouse click,the contextmenu
will popup.
I tried adding rectangle1.contextmenu.isopen=true
in the rectangle's MouseDown
event.Yes,it opens the contextmenu
.However, the contextmenu
is set to open/pop up above(on top) of the rectangle,i did it by simply adding ContextMenuService.Placement="top"
to the rectangle's XAML.But if i use rectangle1.contextmenu.isopen=true
in the rectangle's MouseDown
event, then the contextmenu
pops up but in the wrong place,it doesn't stay on top any more, rather it follows the mouse.E.g. If i click the right corner of the rectangle,the contextmenu
opens/pops up in the right.This behaviour is very strange,i don't know why this is happening.
Anyway,how do i open the contextmenu
at the top of the rectangle on left mouse click?
UPDATE
What's strange is that no matter what code i add to any of the mouseevent
s,the context menu loses it's placement ! E.g.If i even add MsgBox("abc")
on mouseDown event, and then right click on the rectangle, the context menu is not on top!!