Visual Studio 2017:用户更改选项卡时的事件调用

Visual Studio 2017: Event-call when user changes tab

我正在尝试在 VS 中为 XML 代码编写一个大纲(使用 VSIX 模板中的 SDK 的扩展),我想在用户更改为不同的时得到一个事件调用codeview/document.

然后,我打算检查文档类型,如果确实是 xml 文档,则创建并呈现交互式大纲。

我将如何着手创建这样的挂钩,甚至有必要吗?

编辑

我尝试了以下实现,但我被告知该对象不包含 "GetGlobalService"

的定义
using System;
using System.Runtime.InteropServices;
using EnvDTE;
using Microsoft.VisualStudio.Shell;

[Guid("bc4c5e8f-a492-4a44-9e57-ec9ad945140e")]
public class OutlineWindow : ToolWindowPane
{

    private DTE dte;

    public OutlineWindow() : base(null)
    {
        this.Caption = "OutlineWindow";

        this.Content = new OutlineWindowControl();

        dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
        dte.Events.WindowEvents.WindowActivated += OnWindowActivated;
    }

    private void OnWindowActivated(Window gotFocus, Window lostFocus)
    {
        throw new NotImplementedException();
    }
}

多亏了@stuartd,我才得以成功! 我的问题实际上是我把它放错了 class,继承搞砸了。

public class OutlineManager
{
    private DTE dte;

    public OutlineManager()
    {
        dte = Package.GetGlobalService(typeof(DTE)) as DTE;
        dte.Events.WindowEvents.WindowActivated += OnWindowActivated;
    }

    private void OnWindowActivated(Window gotFocus, Window lostFocus)
    {
        //This is run when a new "window"(panel) gains focus (not only the code window though)
    }
}