So I've got two tool windows in my visual studio extension (package) and I'd like to open up the second window via a button on the first window.
I expected this to be explained here: "How to: Open a Tool Window Programmatically", but it wasn't.
So I've got two tool windows in my visual studio extension (package) and I'd like to open up the second window via a button on the first window.
I expected this to be explained here: "How to: Open a Tool Window Programmatically", but it wasn't.
You should use either
Package.FindToolWindow
orIVsUIShell.FindToolWindow
to find or create a tool window.If used from your own package (or if you have a reference to the package, just put it there instead of this):
If you can't do it from your package, or don't have a reference to it, use IVSUIShell:
Here's how I solved it, the following code is the code-behind method of the button on the first window:
You should find the "WindowGUID" in the Guids class and above the class of the ToolWindow.
When you create a new package with toolwindow support, you get a single toolwindow and a command that displays it. This command is handled in the package class with the ShowToolWindow method.
Examining that, you'll see that the base package object has a FindToolWindow method that you can use to find (and create if needed) any toolwindow you have implemented in your package. That FindToolWindow method is just a nice wrapper around the IVsUIShell.FindToolWindow method, which is what ultimately gets invoked when displaying any toolwindow.
So instead of using the old EnvDTE automation interface, I would recommend using the lower level services built into the actual package object.