Abhi
Abhi

Reputation: 5561

How can I add Context Menu Items to C# Editor of Visual Studio?

I found some example where we can add context menu items to C# code editor at compile time but not at runtime. How can we do this at run-time.

Upvotes: 1

Views: 899

Answers (1)

Carlos Quintero
Carlos Quintero

Reputation: 4414

Buttons belonging to commands are always added to commandbars (menus, toolbars, context menus) when the extension is registered within Visual Studio (a one-time event).

What can be customized is whether the command is enabled/disabled and whether buttons created from it are visible/invisible. This can be customized:

1) When the extension is not loaded yet, it is done in the .vsct file through command flags such as DefaultDisabled, DefaultInvisible, etc or VisibilityConstraints.

2) When the extension is loaded, it is done using the DynamicVisibility command flag in .vsct file and OleMenuCommand.BeforeQueryStatus Event. See for example: Dynamic Menu Commands in Visual Studio Packages – Part 2

Upvotes: 2

Related Questions