I have a ListBox with items, and have assigned a ContextMenu to it with three menu items. Everything is working fine except that one of the menu items launches a lengthy operation. I would like to close the ContextMenu from the handler, and maybe display an hour-glass cursor or something.
Can that be done? Or, should I be using a Popup instead? If so, how do I use a Popup in lieu of a ContextMenu? My assumption is I would have to manage it completely - placement and lifetime.
Thanks!
A ContextMenu is attached to a specific control. The ContextMenu element enables you to present users with a list of items that specify commands or options that are associated with a particular control, for example, a Button. Users right-click the control to make the menu appear.
window. ShowDialog(); Close method of the Window class is used to close a window. The following code snippet calls the Close method to close a window.
Answers. You can either just host the Page in a Frame. Alternatively, just make a new Window, and put the same xaml content in the Window class. Migrate any code in the code behind to your new Window class.
What you want is:
myContextMenu.IsOpen = false;
Be sure to call this before your lengthy operation occurs. Depending on your operation, you may want to consider making it asynchronous by performing the operation on another thread - that way, you won't halt the application thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With