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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.