Click here to Skip to main content
15,893,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My context menu has multiple menu items, each of which contains a listbox with the selections. After the user selects an item from the listbox, the context menu closes. I want to force the context menu to stay open, so the user can move to the next menu item and select from its list box. I've tried using contextMenu.StaysOpen = true; and menuItem.StaysOpenOnClick; however, I can't get the menu to stay open.

Here is a snippet of my code:
contextMenu = new ContextMenu();

enrMenuItem = new MenuItem();
enrMenuItem.StaysOpenOnClick = true;
enrMenuItem.Header = "Enrichment";
enrMenuItem.Items.Add(enrMenuListBox);
contextMenu.Items.Add(enrMenuItem);

gadMenuItem = new MenuItem();
gadMenuItem.StaysOpenOnClick = true;
gadMenuItem.Header = "Gadolinia";
gadMenuItem.Items.Add(gadMenuListBox);
contextMenu.Items.Add(gadMenuItem);

contextMenu.IsOpen = true;
Posted

1 solution

Make sure you are using .net 3.0 up. Otherwise, just store the position of the popup when shown and when a selection is made (of when hidden) just show it again at the stored position.

Good luck!
 
Share this answer
 
Comments
OldSchoolToC# 13-Jul-10 20:57pm    
Thanks so much for your answer. I understood it to say that I should store the position and re-show if I'm not using .net 3.0 or up. I am using .net 3.5, so is there something different you would suggest for .net 3.0 and up?
E.F. Nijboer 14-Jul-10 9:33am    
Maybe you could use the StaysOpen property of the ContextMenu. You are now only setting the MenuItem property and this is not exacly what you want I guess. It should now stay open until you set the IsOpen property to false yourself.

Extra info:
http://msdn.microsoft.com/en-us/library/system.windows.controls.contextmenu.staysopen.aspx

Good luck!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900