开发者

Right click context menu to adornment - Doesn't work and invokes the editor menu instead (VS2010)

开发者 https://www.devze.com 2023-01-19 18:23 出处:网络
I\'ve made a Control in XAML and added it to the adornment layer, in the control I have a section that should sp开发者_运维问答awn a context menu when right clicked (using TextBox.ContextMenu property

I've made a Control in XAML and added it to the adornment layer, in the control I have a section that should sp开发者_运维问答awn 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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消