Cancelling the Opening of the Context Menu

Mar 16, 2011 at 5:45 PM
Edited Mar 16, 2011 at 5:46 PM


First off I would like to say that I really like the control you have created. It makes using Context Menus so much easier that the standard ToolKit version.

I had a question/suggestion. I am looking to cancel the opening of the context menu when the user clicks on the Header of the datagrid but display the menu when they click on a DataGridRow. I couldn't find any properties that would allow this. So I have temporaily added one called IsOpeningCancelled. I check this value in the Open method of the PopupMenuBase and if it is set to true then exit out. It seems to work, though not knowing the details of your code I am not sure if it would cause other problems.

If you could let me know if there is already a process to do this that I have missed or if you see any issue with what I have done please let me know.

Thank you again for all you work on this control!


Example of the change:


OverlayCanvas.Opacity = 0; // Make sure the root grid is hidden before repositioning

IsOpening = true;

if (Opening != null)
	Opening(triggerElement, e);

if (IsOpeningCancelled)
     IsOpening = false;
     IsOpeningCancelled = false;

Mar 17, 2011 at 9:05 AM

Hi Mustng65,

Nice suggestion!! Up to now you could only modify menu items just before it was open but there was no easy way to cancel it.

The changes you requested have been implemented in the latest change set below:



Mar 17, 2011 at 4:51 PM

Thank you for your quick response!