This is the final post in a series detailing how to build dynamic menu commands in Visual Studio packages. The previous posts are located here:
- Part 1 – Discusses UI Contexts and how to utilize the built-in ones for dynamic menu commands.
- Part 2 – Discusses the use of the BeforyQueryStatus event to provide more flexibility than built-in UI contexts.
What we’ve explored to date is a way to provide dynamic menu commands (e.g. dynamic visibility, enabled state) in our own package, and the techniques that I’ve shown thus far have worked well for this scenario. However, if you want to develop multiple menu commands or even multiple packages that rely on a custom condition (as shown in Part 2), then you’re stuck implementing the same logic in an event handler for the BeforeQueryStatus event for each OleMenuCommand.
Wouldn’t it be great if we could create our own UI Context, similar to the built-in ones like UIContext_NoSolution or UIContext_FullScreenMode? That way we can create multiple menu commands that rely on that context or even multiple packages which rely on it.
And that’s exactly what this post will cover. We’ll use the solution starting from where we left off at the end of Part 2.