Question

Create ContextMenu on the fly from code

Posted 8 years ago by Avatar Robert Croshere
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 8 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Robert,

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

Actipro Software Support
Posted 8 years ago by Robert Croshere
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 8 years ago by Actipro Software Support - Cleveland, OH, USA
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 8 years ago by Robert Croshere
Ok, thanks, I'll wait for that then. Any idea when the next release is expected?

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

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

Actipro Software Support
Information The latest build of this product (2018.1 build 0231) was released 29 days ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.