I'm developing an extension for Visual Studio 2017 which contains custom "toolwindow". This "toolwindow" contains WPF control
with a view model
subscribed to the Workspace.WorkspaceChanged and EnvDTE.DTE.Events.WindowEvents.WindowActivated events.
I know that when the "toolwindow" is closed by user it's not actually destroyed but rather "hidden". However, it still reacts to my events.
So, I want to know answers for two questions:
- How to check that the tool window is hidden?
- Can I "close" the tool window so it will be destroyed?
EDIT: The code to create tool window:
protected virtual TWindow OpenToolWindow()
{
ThreadHelper.ThrowIfNotOnUIThread();
// Get the instance number 0 of this tool window. This window is single instance so this instance
// is actually the only one.
// The last flag is set to true so that if the tool window does not exists it will be created.
ToolWindowPane window = Package.FindToolWindow(typeof(TWindow), id: 0, create: true);
if (window?.Frame == null)
{
throw new NotSupportedException("Cannot create tool window");
}
IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame;
Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show());
return window as TWindow;
}