I’ve made a Control in XAML and added it to the adornment layer, in the control I have a section that should spawn a context menu when right clicked (using TextBox.ContextMenu property). I’ve tested it in a regular WPF Window and it works great. However, when I tried the same in Visual Studio on an adornment layer I only got the VS2010 editor context menu.
I also tried now to use a regular MouseRightButtonUp event, which does seem to work (the event arrives to the function). However, as soon the event function exits, the Editor context menu jumps up.
- How can I make the regular
context menu to work? - If there is
no way, how can I prevent the editor
context menu from jumping after
MouseRightButtonUp function? - (Follow up to #2) How do I invoke
the context menu manually from
MouseRightButtonUp?
Thank you,
Vitaly
In your right button up handler, are you marking the event as handled? If not, the editor will see the event after your handler is finished. If you are marking it as handled and it still isn’t working, there’s another option.
The more “official” way to do it is to implement an IMouseProcessorProvider + MouseProcessorBase. You’ll need to override
PreprocessMouseRightButtonUp, though only when your adornment is the element that was clicked. This is how the normal editor context menu code works; it implements one of these mouse processors, handles right clicks, and asks the Visual Studio shell to show a context menu at the click location (by sending the SHOWCONTEXTMENU command).If you go this route, your mouse processor provider should have this metadata (typed by hand, sorry for any typos):