Create ContextMenu on the fly from code

Silverlight Studio and Shared Library for Silverlight Forum

Posted 13 years ago by Robert Croshere
Version: 10.2.0105
Avatar
Hi,

I need to create a context menu for a Silverlight control on demand; i.e. when the user right clicks on the control I want to create the context menu and display it. I know I can use the ContextMenuService, however, calling ContextMenuService.SetContextMenu(..) from the MouseRightButtonDown event seems to be too late (I assume the ContextMenuServic hooks the MouseRightButtonDown event) and the menu only gets displayed when clicked for the second time (or more). I also tried displaying the ContextMenu myself, however, the PopupOffset property of the ContextMenu class is internal, so I have no way of positioning the context menu. any ideas on how I can get thise to work?

Thanks,
Robert

Comments (5)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Robert,

Here is an example of dynamically showing a ContextMenu:
http://www.c-sharpcorner.com/uploadfile/dpatra/1107/


Actipro Software Support

Posted 13 years ago by Robert Croshere
Avatar
That article doesn't help much as it is based on the ContextMenu in the Silverlight Toolkit. That control exposes HorizontalOffset and VerticalOffset properties. I'm using the Actipro ContextMenu, which doesn't have those properties, so I have no idea on how to place the context menu at the mouse position.

Robert
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Robert,

Sorry, you're right. I thought we had the HorizontalOffset and VerticalOffset properties like the Silverlight Toolkit version. I've added those properties to our ContextMenu for the next release, so you can set an offset like in the link above.


Actipro Software Support

Posted 13 years ago by Robert Croshere
Avatar
Ok, thanks, I'll wait for that then. Any idea when the next release is expected?

Regards,
Robert
Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Robert,

We'll try and get one out in the next couple weeks.


Actipro Software Support

The latest build of this product (v18.1 build 0233) was released 4 years ago, which was after the last post in this thread.