views:

15

answers:

1

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.

  1. How can I make the regular context menu to work?
  2. If there is no way, how can I prevent the editor context menu from jumping after MouseRightButtonUp function?
  3. (Follow up to #2) How do I invoke the context menu manually from MouseRightButtonUp?

Thank you, Vitaly

+2  A: 

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):

[Export(typeof(IMouseProcessorProvider))]
[Name("WhateverYouWantToCallIt")]
[Order(Before = "VisualStudioMouseProcessor")]
[ContentType("text")] // or whatever your adornment is specific to
[TextViewRole(PredefinedTextViewRoles.Interactive)]
internal sealed class MouseProcProvider : IMouseProcessorProvider
Noah Richards
Hi Noah. Thank you for the answer. I indeed just needed to mark the event as handled to make it work. I'll avoid the "official" way for now, unless I encounter problems with the easier way, but I'll keep it mind. Thanks again!
VitalyB